-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: login with Google, Facebook, Microsoft #89
feat: login with Google, Facebook, Microsoft #89
Conversation
private val configFile = File.createTempFile("config", null) | ||
.also { | ||
it.writeText(configJson) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, better to create the config file on build time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to gradle realisation
@k1rill what if Also, Is there a provision to conceal specific social login options in the current implementation? |
c4abc04
to
bfb58db
Compare
@farhan-arshad-dev this realisation is for edX as for now, so all config fields are required. |
46e8bca
to
f4bd187
Compare
@k1rill and I have discussed and resolved all critical issues. |
b9aae4b
to
b094567
Compare
@farhan-arshad-dev waiting for your review, please take a look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unable to test the Google & Microsoft login due to keys issue.
@k1rill Please rebase the code with the latest the develop branch and use the colors from Colors.kt
auth/src/main/java/org/openedx/auth/presentation/signin/SignInViewModel.kt
Outdated
Show resolved
Hide resolved
auth/src/main/java/org/openedx/auth/presentation/signin/SignInViewModel.kt
Show resolved
Hide resolved
auth/src/main/java/org/openedx/auth/presentation/sso/GoogleAuthHelper.kt
Show resolved
Hide resolved
auth/src/main/java/org/openedx/auth/presentation/signin/compose/SignInView.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm currently looking at how we can test Microsoft login, cuz with the available keys|configs are not working with the current implementation.
6f73afc
to
7ebb9c0
Compare
7ebb9c0
to
d9abb77
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the manual testing, Results are as follows.
- Microsoft login working as expected with some code changes.
- Unable to log-in with Facebook need to check the implementation.
- Unable to log-in with Google need to verify the configs on our side.
core/build.gradle
Outdated
def social = config.get("SOCIAL") | ||
def facebookAppId = social.getOrDefault("FACEBOOK_APP_ID", "") | ||
def facebookClientToken = social.getOrDefault("FACEBOOK_CLIENT_TOKEN", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should handle the case if keys are not available. e.g SOCIAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
default_config/dev/config.yaml
Outdated
SOCIAL: | ||
GOOGLE_CLIENT_ID: "" | ||
FACEBOOK_APP_ID: "" | ||
FACEBOOK_CLIENT_TOKEN: "" | ||
MICROSOFT_CLIENT_ID: "" | ||
MICROSOFT_PACKAGE_SIGNATURE: "" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the config format as follows
SOCIAL_AUTH_ENABLED: true | false
GOOGLE:
ENABLED: true | false
CLIENT_ID: ''
MICROSOFT:
ENABLED: true | false
CLIENT_ID: ''
PACKAGE_SIGNATURE: ''
FACEBOOK:
ENABLED: true | false
FACEBOOK_APP_ID: ''
CLIENT_TOKEN: ''
Reasons:
- iOS used the same format.
- Allows the developer to disable | enable a particular Social auth.
- Allows to disable the social auth and retain the key if want.
- Minimum effort of migration to new configs.
ps: Can create the config changes PR like pull#157
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
client_id : clientId, | ||
authorization_user_agent : "DEFAULT", | ||
redirect_uri : "msauth://$applicationId/$sign", | ||
account_mode : "SINGLE", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, edx microsoft config only supports `account_mode : "MULTIPLE" for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
suspendCancellableCoroutine { continuation -> | ||
val clientApplication = | ||
PublicClientApplication.createSingleAccountPublicClientApplication( | ||
activityContext, | ||
R.raw.microsoft_auth_config | ||
) | ||
val params = AcquireTokenParameters.Builder() | ||
.startAuthorizationFromActivity(activityContext) | ||
.withScopes(SCOPES) | ||
.withCallback(object : AuthenticationCallback { | ||
override fun onSuccess(authenticationResult: IAuthenticationResult?) { | ||
continuation.resume(authenticationResult?.accessToken) | ||
} | ||
|
||
override fun onError(exception: MsalException) { | ||
logger.e { "Microsoft auth error: $exception" } | ||
continuation.resumeWithException(exception) | ||
} | ||
|
||
override fun onCancel() { | ||
logger.d { "Microsoft auth canceled" } | ||
continuation.resume("") | ||
} | ||
}).build() | ||
clientApplication.acquireToken(params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to update the code as per account_mode : "MULTIPLE"
.
can use the following.
suspendCancellableCoroutine { continuation ->
PublicClientApplication.createMultipleAccountPublicClientApplication(activityContext,
R.raw.microsoft_auth_config,
object : IPublicClientApplication.IMultipleAccountApplicationCreatedListener {
override fun onCreated(application: IMultipleAccountPublicClientApplication) {
application.acquireToken(
AcquireTokenParameters.Builder()
.startAuthorizationFromActivity(activityContext)
.withScopes(SCOPES)
.withCallback(object : AuthenticationCallback {
override fun onSuccess(authenticationResult: IAuthenticationResult?) {
continuation.resume(authenticationResult?.accessToken)
}
override fun onError(exception: MsalException) {
logger.e { "Microsoft auth error: $exception" }
continuation.resumeWithException(exception)
}
override fun onCancel() {
logger.d { "Microsoft auth canceled" }
continuation.resume("")
}
})
.build()
)
}
override fun onError(exception: MsalException) {
logger.e { "Microsoft auth error: $exception" }
continuation.resumeWithException(exception)
}
})
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've talked with @farhan-arshad-dev (who isn't available today) and per his feedback we're good to go with merging this PR. I'm approving the PR on his behalf.
@volodymyr-chekyrta feel free to approve & merge the PR, thanks! 🚀
Added Sign In buttons for:
SDK integration guides:
https://developer.android.com/training/sign-in/credential-manager
https://developers.facebook.com/docs/facebook-login/android/
https://github.com/AzureAD/microsoft-authentication-library-for-android
To turn on this feature you need to set
ffShowSocialLogin
flag to true in theconfig.yaml
file.Also in the
config.yaml
was added new configuration fields:Screenshots: