private async void Authenticate(object sender, EventArgs e) { var browser = new SystemBrowser(); _redirectUri = string.Format($"http://127.0.0.1:{browser.Port}"); var options = new OidcClientOptions { Authority = ConfigurationManager.AppSettings["Authority"], ClientId = _clientIdentifier, ClientSecret = "secret", Scope = "openid profile offline_access " + _scope, RedirectUri = _redirectUri, Browser = browser, //FilterClaims = false, Policy = new Policy { Discovery = new DiscoveryPolicy { ValidateEndpoints = false, ValidateIssuerName = false } } }; var oidcClient = new OidcClient(options); var loginRequest = new LoginRequest(); var result = await oidcClient.LoginAsync(loginRequest); if (result.IsError) { _accessToken = null; _identityToken = null; _refreshToken = null; txtIdentityToken.Text = "Error"; txtAccessToken.Text = "Error"; } else { _accessToken = result.AccessToken; _identityToken = result.IdentityToken; _refreshToken = result.RefreshToken; } txtIdentityToken.Text = JWTTokenHelper.ReadToken(_identityToken); txtAccessToken.Text = JWTTokenHelper.ReadToken(_accessToken); }
private async void RefreshTokens(object sender, EventArgs e) { var options = new OidcClientOptions { Authority = _authority, ClientId = _clientIdentifier, RedirectUri = _redirectUri }; var oidcClient = new OidcClient(options); var result = await oidcClient.RefreshTokenAsync(_refreshToken); if (result.IsError) { txtIdentityToken.Text = "Error"; txtAccessToken.Text = "Error"; } else { _accessToken = result.AccessToken; _refreshToken = result.RefreshToken; txtIdentityToken.Text = JWTTokenHelper.ReadToken(_identityToken); txtAccessToken.Text = JWTTokenHelper.ReadToken(_accessToken); } }