protected string GenerateToken(AuthServerRequest authRequest, string issuer, IAdditionalClaimsProvider additionalClaimsProvider) { WebToken tokenObject = new WebToken(); tokenObject.Issuer = issuer; List <KeyValuePair <string, string> > additionalClaims = null; if (authRequest.GrantType == "password") { tokenObject.AddClaim(ClaimTypes.Name, authRequest.Username); if (!string.IsNullOrEmpty(authRequest.ClientId)) { tokenObject.AddClaim("ClientId", authRequest.ClientId); } additionalClaims = additionalClaimsProvider.GetAdditionalUserClaims(authRequest.Username); } else if (authRequest.GrantType == "client") { tokenObject.AddClaim("ClientId", authRequest.ClientId); additionalClaims = additionalClaimsProvider.GetAdditionalClientClaims(authRequest.ClientId); } if ((additionalClaims != null) && (additionalClaims.Count > 0)) { foreach (var kvp in additionalClaims) { tokenObject.AddClaim(kvp.Key, kvp.Value); } } return(tokenObject.GenerateToken(_crypter, _options.CryptionKey)); }
public static void TestWebTokens() { Crypt crypt = new Crypt(); string key = "LL132-xzJ41-N11!"; WebToken token = new WebToken(); token.CreatedDate = DateTime.Now; token.Issuer = "Test Issuer"; token.AddClaim("username", "admin"); token.AddClaim("cityofbirth", "ParaƱaque"); string encryptedToken = token.GenerateToken(crypt, key); WebToken decryptedToken = WebToken.DecryptToken(encryptedToken, crypt, key); var dummy = 3; }