コード例 #1
0
        public static void RedirectToLogin(UIViewController viewController, LoadingOverlay loadingOverlay)
        {
            PreferenceHandler.setLoggedIn(false);
            PreferenceHandler.SetToken(string.Empty);
            var LoginViewController = (LoginViewController)viewController.Storyboard.InstantiateViewController("LoginViewController");

            viewController.NavigationController.PushViewController(LoginViewController, false);
        }
コード例 #2
0
        public static async Task GetToken()
        {
            string tokenURL = string.Format(B2CConfig.TokenURL, B2CConfig.Tenant, B2CPolicy.SignInPolicyId, B2CConfig.ClientId, PreferenceHandler.GetAccessCode());
            var    response = await InvokeApi.Authenticate(tokenURL, string.Empty, HttpMethod.Post);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                string strContent = await response.Content.ReadAsStringAsync();

                var tokenNew = JsonConvert.DeserializeObject <AccessToken>(strContent);
                PreferenceHandler.SetToken(tokenNew.id_token);
                PreferenceHandler.SetRefreshToken(tokenNew.refresh_token);
            }
        }
コード例 #3
0
        public static async Task RefreshToken(UIViewController viewController, LoadingOverlay loadingOverlay)
        {
            string tokenURL = string.Format(B2CConfig.RefreshTokenURL, B2CConfig.Tenant, B2CPolicy.SignInPolicyId, B2CConfig.ClientId, PreferenceHandler.GetRefreshToken());
            var    response = await InvokeApi.Authenticate(tokenURL, string.Empty, HttpMethod.Post);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                string strContent = await response.Content.ReadAsStringAsync();

                var tokenNew = JsonConvert.DeserializeObject <AccessToken>(strContent);
                PreferenceHandler.SetToken(tokenNew.id_token);
                PreferenceHandler.SetRefreshToken(tokenNew.refresh_token);
            }
            else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest || response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                RedirectToLogin(viewController, loadingOverlay);
            }
        }