/// <summary>
 /// Huawei Api Client authorized login method
 /// </summary>
 /// <param name="activity">Call the Activity page handle of the singIn interface</param>
 public void SingIn(Activity activity)
 {
     if (authParams == null)
     {
         authParams = InitData();
     }
     service = HuaweiIdAuthManager.GetService(activity, authParams);
     activity.StartActivityForResult(service.SignInIntent, REQUEST_SIGN_IN_LOGIN);
 }
        /// <summary>
        /// Signing In with HUAWEI ID (Authorization Code)
        /// </summary>
        private void SignInCode()
        {
            authParam = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DefaultAuthRequestParam)
                        .SetProfile()
                        .SetAuthorizationCode()
                        .CreateParams();
            authManager = HuaweiIdAuthManager.GetService(this, authParam);

            StartActivityForResult(authManager.SignInIntent, Constant.RequestSignInLoginCode);
        }
        /// <summary>
        /// Signing In with HUAWEI ID (ID Token)
        /// </summary>
        private void SignIn()
        {
            authParam = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DefaultAuthRequestParam)
                        .SetIdToken()
                        .SetAccessToken()
                        .CreateParams();
            authManager = HuaweiIdAuthManager.GetService(this, authParam);

            StartActivityForResult(authManager.SignInIntent, Constant.RequestSignInLogin);
        }
Пример #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);
        }
 private HmsProxyImpl()
 {
     authParams = InitData();
 }
Пример #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);
            }
        }