public async Task<AccessTokenIntrospectionResult> IntrospectTokenAsync(string accessToken, bool allowOfflineValidation = false) { var accessTokenType = AccessTokenAnalyzer.GetTokenType(accessToken); var discoveryResponse = await _discoveryDocumentProvider.GetDiscoveryDocumentAsync(); if (accessTokenType == AccessTokenType.Jwt && allowOfflineValidation) { var claims = JwtSecurityTokenVerifier.Verify(accessToken, _identityServer4Info.AllowedScope, discoveryResponse); return new AccessTokenIntrospectionResult(accessTokenType, claims, true); } var introspectionResult = await IntrospectTokenOnlineAsync(accessToken, accessTokenType, discoveryResponse); return introspectionResult; }
private string TryToOptimize(string accessToken) { var accessTokenType = AccessTokenAnalyzer.GetTokenType(accessToken); if (accessTokenType == AccessTokenType.Reference) { return(accessToken); } using (var sha256 = SHA256.Create()) { byte[] hashValue = sha256.ComputeHash(Encoding.UTF8.GetBytes(accessToken)); var sb = new StringBuilder(); // ReSharper disable once ForCanBeConvertedToForeach for (int i = 0; i < hashValue.Length; i++) { sb.Append(hashValue[i].ToString("x2")); } return(sb.ToString()); } }