public void Authenticate(Action <AuthServiceResult> callback)
        {
            if (!m_initialized)
            {
                Debug.Log("AppGalleryService -> CreateAuthParams");
                var authParams = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM_GAME).SetIdToken().SetAccessToken().CreateParams();
                Debug.Log("AppGalleryService -> GetService");
                m_authService = HuaweiIdAuthManager.GetService(authParams);

                m_initialized = true;
            }

            Debug.Log("AppGalleryService -> Start SignOut");
            var signOut = m_authService.SignOut();

            signOut.AddOnSuccessListener(success =>
            {
                Debug.Log($"AppGalleryService -> SignOut Success");
                SignIn(callback);
            });
            signOut.AddOnFailureListener(error =>
            {
                Debug.Log($"AppGalleryService -> SignOut Error {error.Message}");
                SignIn(callback);
            });
        }
Exemplo n.º 2
0
 private void InitHuaweiAuthService()
 {
     if (_authService == null)
     {
         var authParams = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM_GAME).SetIdToken().CreateParams();
         _authService = HuaweiIdAuthManager.GetService(authParams);
         Debug.Log(TAG + " authservice is assigned.");
     }
 }
Exemplo n.º 3
0
        private void FabOnClick(object sender, EventArgs eventArgs)
        {
            //View view = (View) sender;
            //Snackbar.Make(view, "Replace with your own action", Snackbar.LengthLong)
            //    .SetAction("Action", (Android.Views.View.IOnClickListener)null).Show();
            HuaweiIdAuthParams   authParams = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DefaultAuthRequestParam).SetIdToken().CreateParams();
            IHuaweiIdAuthService service    = HuaweiIdAuthManager.GetService(this, authParams);

            StartActivityForResult(service.SignInIntent, 8888);
        }
Exemplo n.º 4
0
        private void ImgHuaweiId_Click(object sender, EventArgs e)
        {
            HuaweiIdAuthParamsHelper huaweiIdAuthParamsHelper = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DefaultAuthRequestParam);
            List <Scope>             scopeList = new List <Scope>();

            scopeList.Add(new Scope(HwIDConstant.SCOPE.AccountBaseprofile));
            huaweiIdAuthParamsHelper.SetScopeList(scopeList);
            HuaweiIdAuthParams   authParams = huaweiIdAuthParamsHelper.SetAccessToken().CreateParams();
            IHuaweiIdAuthService service    = HuaweiIdAuthManager.GetService(this, authParams);

            StartActivityForResult(service.SignInIntent, SignCode);
        }
        /// <summary>
        /// Initialize and return the HuaweiIdSignInOptions object
        /// </summary>
        private HuaweiIdAuthParams InitData()
        {
            IList <Scope> scopeList = new List <Scope>();

            scopeList.Add(HuaweiIdAuthAPIManager.HuaweiidBaseScope);
            scopeList.Add(new Scope(DriveScopes.ScopeDrive));
            scopeList.Add(new Scope(DriveScopes.ScopeDriveFile));
            scopeList.Add(new Scope(DriveScopes.ScopeDriveMetadata));
            scopeList.Add(new Scope(DriveScopes.ScopeDriveMetadataReadonly));
            scopeList.Add(new Scope(DriveScopes.ScopeDriveReadonly));
            scopeList.Add(new Scope(DriveScopes.ScopeDriveAppdata));

            HuaweiIdAuthParams mParams = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DefaultAuthRequestParam).SetAccessToken().SetIdToken().SetScopeList(scopeList).CreateParams();

            return(mParams);
        }
Exemplo n.º 6
0
        //Sign-in and authorization method.
        //The authorization screen will display up if authorization has not granted by the current account.
        private async void SignIn()
        {
            Log.Info(TAG, "Begin sign in");
            IList <Scope> scopeList = new List <Scope>();

            // Add scopes to apply for. The following only shows an example.
            // Developers need to add scopes according to their specific needs.

            // View and save steps in HUAWEI Health Kit.
            scopeList.Add(new Scope(Scopes.HealthkitStepRead));
            scopeList.Add(new Scope(Scopes.HealthkitStepWrite));
            // View and save height and weight in HUAWEI Health Kit.
            scopeList.Add(new Scope(Scopes.HealthkitHeightweightRead));
            scopeList.Add(new Scope(Scopes.HealthkitHeightweightWrite));
            // View and save the heart rate data in HUAWEI Health Kit.
            scopeList.Add(new Scope(Scopes.HealthkitHeartrateRead));
            scopeList.Add(new Scope(Scopes.HealthkitHeartrateWrite));
            // View and save activityRecord in HUAWEI Health Kit.
            scopeList.Add(new Scope(Scopes.HealthkitActivityRead));
            scopeList.Add(new Scope(Scopes.HealthkitActivityWrite));
            // View and save sleep data in HUAWEI Health Kit.
            scopeList.Add(new Scope(Scopes.HealthkitSleepRead));
            scopeList.Add(new Scope(Scopes.HealthkitSleepWrite));
            // Configure authorization parameters.
            HuaweiIdAuthParamsHelper AuthParamsHelper = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DefaultAuthRequestParam);
            HuaweiIdAuthParams       AuthParams       = AuthParamsHelper.SetIdToken().SetAccessToken().SetScopeList(scopeList).CreateParams();

            // Initialize the HuaweiIdAuthService object.
            AuthService = HuaweiIdAuthManager.GetService(this, AuthParams);

            // Silent sign-in. If authorization has been granted by the current account,
            // the authorization screen will not display. This is an asynchronous method.
            var AuthHuaweiIdTask = AuthService.SilentSignInAsync();

            try
            {
                await AuthHuaweiIdTask;

                if (AuthHuaweiIdTask.IsCompleted && AuthHuaweiIdTask.Result != null)
                {
                    if (AuthHuaweiIdTask.Exception == null)
                    {
                        Log.Info(TAG, "SilentSignIn success");
                        Toast.MakeText(this, "SilentSignIn success", ToastLength.Long).Show();

                        // anfter Huawei ID authorization, perform Huawei Health authorization.
                        CheckOrAuthorizeHealth();
                    }
                    else
                    {
                        // The silent sign-in fails.
                        // This indicates that the authorization has not been granted by the current account.
                        Log.Info(TAG, "Sign failed status:" + AuthHuaweiIdTask.Exception.Message);
                        Log.Info(TAG, "Begin sign in by intent");

                        // Call the sign-in API using the getSignInIntent() method.
                        Intent signInIntent = AuthService.SignInIntent;

                        // Display the authorization screen by using the startActivityForResult() method of the activity.
                        StartActivityForResult(signInIntent, Constants.RequestSignInLogin);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Info(TAG, "Sign failed :" + ex.Message);
                Log.Info(TAG, "Begin sign in by intent");
                // Call the sign-in API using the getSignInIntent() method.
                Intent signInIntent = AuthService.SignInIntent;

                // Display the authorization screen by using the startActivityForResult() method of the activity.
                StartActivityForResult(signInIntent, Constants.RequestSignInLogin);
            }
        }