Beispiel #1
0
        public JwtSecurityToken GetToken(JwtManagerOptions options)
        {
            switch (options.GrantType)
            {
            case ArcadePocketsGrantType.ResourceOwner:
                return(GetTokenWithPassword(options));

            default:
                return(null);
            }
        }
Beispiel #2
0
        public JwtSecurityToken GetRefreshToken(JwtManagerOptions options, string refreshToken = "")
        {
            switch (options.GrantType)
            {
            case ArcadePocketsGrantType.ResourceOwner:
            {
                if (string.IsNullOrEmpty(refreshToken))
                {
                    return(GetTokenWithPassword(options));
                }
                else
                {
                    return(GetTokenFromRefreshToken(refreshToken, options));
                }
            }

            default:
                return(null);
            }
        }
Beispiel #3
0
        private JwtSecurityToken GetTokenFromRefreshToken(string refreshToken, JwtManagerOptions options)
        {
            var request = new HttpRequestMessage(HttpMethod.Post, options.TokenIssuerUri);

            var keyValues = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("client_id", options.ClientID),
                new KeyValuePair <string, string>("client_secret", options.ClientSecret),
                new KeyValuePair <string, string>("grant_type", "refresh_token"),
                new KeyValuePair <string, string>("refresh_token", refreshToken)
            };

            request.Content = new FormUrlEncodedContent(keyValues);

            var bearerResult = _httpClient.SendAsync(request).Result;
            var bearerData   = bearerResult.Content.ReadAsStringAsync().Result;

            JwtSecurityToken token = JsonConvert.DeserializeObject <JwtSecurityToken>(bearerData);

            return(token);
        }
 public JwtManager(IMemoryCache cache, IOptions <JwtManagerOptions> options)
 {
     _cache   = cache;
     _options = options.Value;
 }