public string Protect(AuthenticationTicket data) { if (data == null) { throw new ArgumentNullException("data"); } string clientId = ConfigurationManager.AppSettings.Get("ClientIdApi"); if (string.IsNullOrWhiteSpace(clientId)) { throw new InvalidOperationException("AuthenticationTicket.Properties does not include AccessData"); } AccessData accessData = new AccessDataFactory().Get(); string symmetricKeyAsBase64 = accessData.Base64Secret; byte[] keyByteArray = TextEncodings.Base64Url.Decode(symmetricKeyAsBase64); HmacSigningCredentials signingKey = new HmacSigningCredentials(keyByteArray); DateTimeOffset?issued = data.Properties.IssuedUtc; DateTimeOffset?expires = data.Properties.ExpiresUtc; JwtSecurityToken token = new JwtSecurityToken(_issuer, clientId, data.Identity.Claims, issued.Value.UtcDateTime, expires.Value.UtcDateTime, signingKey); JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler(); string jwt = handler.WriteToken(token); new LogWebApiScmFactory().SaveLog("Token", JsonConvert.SerializeObject(token), "Gerando token", string.Format("Token gerado: {0}", jwt), HttpContext.Current); return(jwt); }
static public DataSet GetAccessSchemas(AccessDataFactory.AccessDataContext info) { return(AccessDataFactory.GetSchemas(info)); }