/// <summary> /// Revoking HUAWEI ID Authorization /// </summary> private void CancelAuthorization() { try { Task cancelAuthorizationTask = authManager.CancelAuthorization(); cancelAuthorizationTask.AddOnCompleteListener ( new OnCompleteListener ( "Cancel Authorization Success", "Cancel Authorization Failed" ) ); } catch (Exception e) { Log.InfoFunc(TAG, "Cancel Authorization failed: " + e.Message); } }
/// <summary> /// Verifying ID Token Validity /// </summary> /// <param name="idToken">provide from service</param> private void ValidateIdToken(string idToken) { if (string.IsNullOrEmpty(idToken)) { Log.InfoFunc(TAG, "ID Token is empty"); } else { IDTokenParser idTokenParser = new IDTokenParser(); try { idTokenParser.Verify(idToken); } catch (System.Exception e) { Log.InfoFunc(TAG, "token verification failed: " + e.Message); } } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == Constant.RequestSignInLogin) { //login success //get user message by ParseAuthResultFromIntent Task authHuaweiIdTask = HuaweiIdAuthManager.ParseAuthResultFromIntent(data); if (authHuaweiIdTask.IsSuccessful) { AuthHuaweiId huaweiAccount = (AuthHuaweiId)authHuaweiIdTask.Result; Log.InfoFunc(TAG, huaweiAccount.DisplayName + " signIn success "); Log.InfoFunc(TAG, "AccessToken: " + huaweiAccount.AccessToken); ValidateIdToken(huaweiAccount.IdToken); } else { Log.InfoFunc(TAG, "signIn failed: " + (authHuaweiIdTask.Exception).ToString()); } } if (requestCode == Constant.RequestSignInLoginCode) { //login success Task authHuaweiIdTask = HuaweiIdAuthManager.ParseAuthResultFromIntent(data); if (authHuaweiIdTask.IsSuccessful) { AuthHuaweiId huaweiAccount = (AuthHuaweiId)authHuaweiIdTask.Result; Log.InfoFunc(TAG, "signIn get code success."); Log.InfoFunc(TAG, "ServerAuthCode: " + huaweiAccount.AuthorizationCode); /**** english doc:For security reasons, the operation of changing the code to an AT must be performed on your server. The code is only an example and cannot be run. ****/ /**********************************************************************************************/ } else { Log.InfoFunc(TAG, "signIn get code failed: " + (authHuaweiIdTask.Exception).ToString()); } } }
/// <summary> /// Signing Out from HUAWEI ID /// </summary> private void SignOut() { try { Task signOutTask = authManager.SignOut(); signOutTask.AddOnSuccessListener ( new OnSuccessListener ( "SignOut Success" ) ).AddOnFailureListener( new OnFailureListener ( "SignOut Failed" ) ); } catch (System.Exception e) { Log.InfoFunc(TAG, "SignOut Failed: " + e.Message); } }