internal async Task RefreshAccessTokenAsync() { // We have a refresh token, lets use that. if (_refreshToken != null) { RequestTokenResponseData data = null; try { data = await MAGRequests.RefreshAccessTokenAsync(_config, _device, _refreshToken); } catch { // TODO If this fails try to use idToken to get access token if (_idToken != null && _idTokenType != null) { data = await MAGRequests.RequestAccessTokenFromIdTokenAsync(_config, _device, _idToken, _idTokenType); } } await UpdateTokens(data); } // We have an id token, lets use that to request an access token. else if (_idToken != null && _idTokenType != null) { var data = await MAGRequests.RequestAccessTokenFromIdTokenAsync(_config, _device, _idToken, _idTokenType); await UpdateTokens(data); } // Lets check if we are anonymous, we can simply just login in again to get an access token. else if (_isAnonymous) { var data = await MAGRequests.RequestAccessTokenAnonymouslyAsync(_config, _device); await UpdateTokens(data); } }
async Task UpdateTokens(RequestTokenResponseData data) { _accessToken = data.AccessToken; _refreshToken = data.RefreshToken; _expireTimeUtc = DateTime.UtcNow.AddSeconds(data.ExpiresIn); if (data.IdToken != null && data.IdTokenType != null) { _idToken = data.IdToken; _idTokenType = data.IdTokenType; } await SaveTokensAsync(); }
private void Complete(MobileConnectStatus response) { _state = null; _nonce = null; _token = response.TokenResponse.ResponseData; accessToken.Text = _token.AccessToken; idToken.Text = _token.IdToken; timeReceived.Text = _token.TimeReceived.ToString("u"); applicationName.Text = _discoveryResponse.ApplicationShortName ?? ""; validationResult.Text = response.TokenResponse.ValidationResult.ToString(); loginPanel.Visibility = Visibility.Collapsed; loggedPanel.Visibility = Visibility.Visible; }