Skip to content
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

Merged
merged 9 commits into from
Dec 11, 2023

Conversation

k1rill
Copy link
Contributor

@k1rill k1rill commented Nov 9, 2023

Added Sign In buttons for:

  • Google
  • Facebook
  • Microsoft

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 the config.yaml file.
Also in the config.yaml was added new configuration fields:

    SOCIAL:
      GOOGLE_CLIENT_ID: ""
      FACEBOOK_APP_ID: ""
      FACEBOOK_CLIENT_TOKEN: ""
      MICROSOFT_CLIENT_ID: ""
      MICROSOFT_PACKAGE_SIGN: ""

Screenshots:
1
2
3
4
5

@k1rill k1rill linked an issue Nov 9, 2023 that may be closed by this pull request
Comment on lines 31 to 34
private val configFile = File.createTempFile("config", null)
.also {
it.writeText(configJson)
}
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to gradle realisation

@farhan-arshad-dev
Copy link
Contributor

@k1rill what if ffShowSocialLogin is set to true, but GOOGLE_CLIENT_ID key is not available? Will the application display the Google sign-in button?

Also, Is there a provision to conceal specific social login options in the current implementation?

@k1rill k1rill force-pushed the feature/social_login branch 4 times, most recently from c4abc04 to bfb58db Compare November 14, 2023 18:23
@k1rill
Copy link
Contributor Author

k1rill commented Nov 15, 2023

@k1rill what if ffShowSocialLogin is set to true, but GOOGLE_CLIENT_ID key is not available? Will the application display the Google sign-in button?

Also, Is there a provision to conceal specific social login options in the current implementation?

@farhan-arshad-dev this realisation is for edX as for now, so all config fields are required.

@volodymyr-chekyrta
Copy link
Contributor

@k1rill and I have discussed and resolved all critical issues.
Everything looks good and ready to merge.

@k1rill k1rill force-pushed the feature/social_login branch from b9aae4b to b094567 Compare November 17, 2023 12:42
@volodymyr-chekyrta
Copy link
Contributor

@farhan-arshad-dev waiting for your review, please take a look

@omerhabib26 omerhabib26 self-requested a review November 27, 2023 08:46
Copy link
Contributor

@omerhabib26 omerhabib26 left a 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

config.yaml Outdated Show resolved Hide resolved
core/src/main/java/org/openedx/core/ApiConstants.kt Outdated Show resolved Hide resolved
core/build.gradle Outdated Show resolved Hide resolved
core/build.gradle Outdated Show resolved Hide resolved
config.yaml Outdated Show resolved Hide resolved
core/src/main/AndroidManifest.xml Outdated Show resolved Hide resolved
Copy link
Contributor

@farhan-arshad-dev farhan-arshad-dev left a 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.

@k1rill k1rill force-pushed the feature/social_login branch 9 times, most recently from 6f73afc to 7ebb9c0 Compare December 4, 2023 20:09
@k1rill k1rill force-pushed the feature/social_login branch from 7ebb9c0 to d9abb77 Compare December 4, 2023 20:14
Copy link
Contributor

@farhan-arshad-dev farhan-arshad-dev left a 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.

Comment on lines 157 to 159
def social = config.get("SOCIAL")
def facebookAppId = social.getOrDefault("FACEBOOK_APP_ID", "")
def facebookClientToken = social.getOrDefault("FACEBOOK_CLIENT_TOKEN", "")
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment on lines 12 to 18
SOCIAL:
GOOGLE_CLIENT_ID: ""
FACEBOOK_APP_ID: ""
FACEBOOK_CLIENT_TOKEN: ""
MICROSOFT_CLIENT_ID: ""
MICROSOFT_PACKAGE_SIGNATURE: ""

Copy link
Contributor

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

Copy link
Contributor Author

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",
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment on lines 21 to 45
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)
Copy link
Contributor

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)
                    }
                })
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link

@miankhalid miankhalid left a 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! 🚀

@volodymyr-chekyrta volodymyr-chekyrta merged commit 73ed462 into openedx:develop Dec 11, 2023
3 checks passed
@k1rill k1rill mentioned this pull request Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] Social Login and Authentication
5 participants