This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Configure the Google Sign in requirements | |
val googleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) | |
.requestIdToken(resources.getString(R.string.google_client)) | |
.requestEmail() | |
.build() | |
val googleSignInClient = GoogleSignIn.getClient(this, googleSignInOptions) | |
loginFormGoogleLoginButton.onClick { | |
startActivityForResult(googleSignInClient.signInIntent, GOOGLE_SIGN_IN) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Register the callback for the Facebook authentication | |
LoginManager.getInstance().registerCallback(callbackManager, object : FacebookCallback<LoginResult> { | |
override fun onSuccess(result: LoginResult?) { | |
result?.let { model.federateWithFacebook(it.accessToken) } | |
[email protected]() | |
} | |
override fun onCancel() { | |
Log.d(TAG, "Facebook authentication is cancelled") | |
toast("Facebook Authentication is cancelled") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Federate with Facebook authentication | |
*/ | |
override fun federateWithFacebook(accessToken: AccessToken) { | |
Log.d(TAG, "Federating with Facebook") | |
thread(start = true) { | |
with(service.identityManager.underlyingProvider) { | |
clear() | |
withLogins(mapOf("graph.facebook.com" to accessToken.token)) | |
refresh() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Register the callback for the Facebook authentication | |
LoginManager.getInstance().registerCallback(callbackManager, object : FacebookCallback<LoginResult> { | |
override fun onSuccess(result: LoginResult?) { | |
Log.d(TAG, "Facebook token = ${result?.accessToken?.token}") | |
toast("Access Token received") | |
} | |
override fun onCancel() { | |
Log.d(TAG, "Facebook authentication is cancelled") | |
toast("Facebook Authentication is cancelled") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Facebook Requirement | |
private val callbackManager: CallbackManager = CallbackManager.Factory.create() | |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
// Handle response from Facebook SDK | |
callbackManager.onActivityResult(requestCode, resultCode, data) | |
super.onActivityResult(requestCode, resultCode, data) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Facebook Requirements --> | |
<meta-data | |
android:name="com.facebook.sdk.ApplicationId" | |
android:value="@string/facebook_app_id"/> | |
<activity | |
android:name="com.facebook.FacebookActivity" | |
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" | |
android:label="@string/app_name"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
custom: | |
amplify: | |
- filename: ../android/app/src/main/res/raw/awsconfiguration.json | |
type: native | |
appClient: AndroidUserPoolClient | |
- filename: ../ios/App/awsconfiguration.json | |
type: native | |
appClient: iOSUserPoolClient | |
- filename: ../web/src/aws-exports.js | |
type: javascript |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressLint("InflateParams") | |
private fun handleLogin() { | |
model.initiateSignin { identityRequest, params, callback -> | |
when(identityRequest) { | |
IdentityRequest.NEED_CREDENTIALS -> { | |
callback(mapOf( | |
"username" to loginFormUsernameField.text.toString(), | |
"password" to loginFormPasswordField.text.toString() | |
)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AuthenticatorViewModel(private val identityRepository: IdentityRepository) : ViewModel() { | |
/** | |
* Current user record, or null if the user is not logged in | |
*/ | |
val currentUser: LiveData<User?> = identityRepository.currentUser | |
/** | |
* Stored user name, or null if the user has never logged in | |
*/ | |
val storedUsername: LiveData<String?> = identityRepository.storedUsername |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun initiateSignin(handler: IdentityHandler) { | |
try { | |
userPool.currentUser.getSessionInBackground(object : AuthenticationHandler { | |
override fun onSuccess(nSession: CognitoUserSession?, newDevice: CognitoDevice?) { | |
val userSession = checkNotNull(nSession) { "user session is null" } | |
storeUserSession(handler, userSession) | |
runOnUiThread { handler(IdentityRequest.SUCCESS, null, DO_NOTHING) } | |
} | |
override fun onFailure(exception: Exception?) = handleFailure(handler, exception?.message) |