本文整理汇总了C#中System.Security.Cryptography.RSACryptoServiceProvider.ToJsonWebKey方法的典型用法代码示例。如果您正苦于以下问题:C# RSACryptoServiceProvider.ToJsonWebKey方法的具体用法?C# RSACryptoServiceProvider.ToJsonWebKey怎么用?C# RSACryptoServiceProvider.ToJsonWebKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.RSACryptoServiceProvider
的用法示例。
在下文中一共展示了RSACryptoServiceProvider.ToJsonWebKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: refresh_Click
private async void refresh_Click(object sender, RoutedEventArgs e)
{
if (_config == null)
{
await LoadOpenIdConnectConfigurationAsync();
}
var tokenClient = new TokenClient(
_config.TokenEndpoint,
_settings.ClientId,
_settings.ClientSecret);
_provider = JwkNetExtensions.CreateProvider();
var jwk = _provider.ToJsonWebKey();
var tokenResponse = await tokenClient.RequestRefreshTokenPopAsync(
refreshToken: _result?.RefreshToken,
algorithm: jwk.Alg,
key: jwk.ToJwkString());
if (tokenResponse.IsError)
{
_result = new LoginResult { ErrorMessage = tokenResponse.Error };
}
else
{
_result = new LoginResult
{
Success = true,
AccessToken = tokenResponse.AccessToken,
RefreshToken = tokenResponse.RefreshToken,
IdentityToken = tokenResponse.IdentityToken,
AccessTokenExpiration = DateTime.Now.AddSeconds(tokenResponse.ExpiresIn)
};
}
ShowTokenResult();
}
示例2: ValidateResponseAsync
private async Task<LoginResult> ValidateResponseAsync(AuthorizeResponse response)
{
// id_token validieren
var tokenClaims = ValidateIdentityToken(response.IdentityToken);
if (tokenClaims == null)
{
return new LoginResult { ErrorMessage = "Invalid identity token." };
}
// nonce validieren
var nonce = tokenClaims.FirstOrDefault(c => c.Type == JwtClaimTypes.Nonce);
if (nonce == null || !string.Equals(nonce.Value, _nonce, StringComparison.Ordinal))
{
return new LoginResult { ErrorMessage = "Inalid nonce." };
}
// c_hash validieren
var c_hash = tokenClaims.FirstOrDefault(c => c.Type == JwtClaimTypes.AuthorizationCodeHash);
if (c_hash == null || ValidateCodeHash(c_hash.Value, response.Code) == false)
{
return new LoginResult { ErrorMessage = "Invalid code." };
}
_provider = JwkNetExtensions.CreateProvider();
var jwk = _provider.ToJsonWebKey();
// code eintauschen gegen tokens
var tokenClient = new TokenClient(
_config.TokenEndpoint,
_settings.ClientId,
_settings.ClientSecret);
var tokenResponse = await tokenClient.RequestAuthorizationCodePopAsync(
code: response.Code,
redirectUri: _settings.RedirectUri,
codeVerifier: _verifier,
algorithm: jwk.Alg,
key: jwk.ToJwkString());
if (tokenResponse.IsError)
{
return new LoginResult { ErrorMessage = tokenResponse.Error };
}
// optional userinfo aufrufen
var profileClaims = new List<Claim>();
if (_settings.LoadUserProfile)
{
var userInfoClient = new UserInfoClient(
new Uri(_config.UserInfoEndpoint),
tokenResponse.AccessToken);
var userInfoResponse = await userInfoClient.GetAsync();
profileClaims = userInfoResponse.GetClaimsIdentity().Claims.ToList();
}
var principal = CreatePrincipal(tokenClaims, profileClaims);
return new LoginResult
{
Success = true,
User = principal,
IdentityToken = response.IdentityToken,
AccessToken = tokenResponse.AccessToken,
RefreshToken = tokenResponse.RefreshToken,
AccessTokenExpiration = DateTime.Now.AddSeconds(tokenResponse.ExpiresIn)
};
}