private async Task StartFlowAsync(string responseType, string scope) { Exception exception = null; try { _response = await WebAuthentication.DoImplicitFlowAsync( new Uri(Constants.AuthorizeEndpoint), "implicitclient", responseType, scope); Output.Text = _response.Raw; ParseResponse(); } catch (Exception ex) { exception = ex; } if (exception != null) { var md = new MessageDialog(exception.ToString()); await md.ShowAsync(); } }
private void webView_Navigating(object sender, NavigatingCancelEventArgs e) { if (e.Uri.ToString().StartsWith(_callbackUri.AbsoluteUri)) { AuthorizeResponse = new AuthorizeResponse(e.Uri.AbsoluteUri); e.Cancel = true; this.Visibility = System.Windows.Visibility.Hidden; if (Done != null) { Done.Invoke(this, AuthorizeResponse); } } }
public static async Task<ExpenseTrackerIdentity> Create(AuthorizeResponse authorizeResponse) { var claims = new List<Claim>(); // call the userinfo endpoint to get identity information, // using the access token. var userInfo = await EndpointAndTokenHelper.CallUserInfoEndpoint(authorizeResponse.AccessToken); // decode the token to get the issuer var decodedIdToken = EndpointAndTokenHelper.DecodeToken(authorizeResponse.IdentityToken); // extract the data that's useful for us JToken sub, iss; if (decodedIdToken.TryGetValue("sub", out sub) && decodedIdToken.TryGetValue("iss", out iss)) { claims.Add(new Claim("unique_user_key", iss.ToString() + "_" + sub.ToString())); } var roles = userInfo.Value<JArray>("role").ToList(); foreach (var role in roles) { claims.Add(new Claim("role", role.ToString())); } // keep the access token - we'll need it afterwards for API access claims.Add(new Claim("access_token", authorizeResponse.AccessToken)); return new ExpenseTrackerIdentity(claims); }
void _login_Done(object sender, AuthorizeResponse e) { _response = e; Textbox1.Text = e.Raw; }
public async void ContinueWebAuthentication(Windows.ApplicationModel.Activation.WebAuthenticationBrokerContinuationEventArgs args) { if (args.WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) { var authResponse = new AuthorizeResponse(args.WebAuthenticationResult.ResponseData); // create & save the information we need related to the user, and the access token App.ExpenseTrackerIdentity = await ExpenseTrackerIdentity.Create(authResponse); // redirect to the first page Frame.Navigate(typeof(ExpenseGroupsView)); } }
public void ContinueWebAuthentication(Windows.ApplicationModel.Activation.WebAuthenticationBrokerContinuationEventArgs args) { Exception exception = null; if (args.WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) { _response = new AuthorizeResponse(args.WebAuthenticationResult.ResponseData); Output.Text = _response.Raw; AccessToken.Text = _response.AccessToken == null ? "" : ParseToken(_response.AccessToken); IdToken.Text = _response.IdentityToken == null ? "" : ParseToken(_response.IdentityToken); } else if (args.WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.UserCancel) { exception = new Exception("User cancelled authentication"); } else if (args.WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp) { exception = new Exception("HTTP Error on AuthenticateAndContinue() : " + args.WebAuthenticationResult.ResponseErrorDetail.ToString()); } else { exception = new Exception("Error on AuthenticateAndContinue() : " + args.WebAuthenticationResult.ResponseStatus.ToString()); } if (exception != null) { var md = new MessageDialog(exception.ToString()); md.ShowAsync(); } }