public async Task <bool> AddToken(GrantedToken grantedToken)
        {
            if (grantedToken == null)
            {
                throw new ArgumentNullException(nameof(grantedToken));
            }

            var id = Guid.NewGuid().ToString();
            await _storage.SetAsync(id, grantedToken, grantedToken.ExpiresIn); // 1. Store tokens.

            await _storage.SetAsync("access_token_" + grantedToken.AccessToken, id, grantedToken.ExpiresIn);

            if (!string.IsNullOrWhiteSpace(grantedToken.IdToken))
            {
                await _storage.SetAsync("access_token_" + grantedToken.IdToken, id, grantedToken.ExpiresIn);
            }

            await _storage.SetAsync("refresh_token_" + grantedToken.RefreshToken, id, grantedToken.ExpiresIn);

            var searchKey     = GetSearchKey(grantedToken);
            var grantedTokens = await _storage.GetValue(searchKey);

            var values = new JArray();

            if (!string.IsNullOrWhiteSpace(grantedTokens))
            {
                values = JArray.Parse(grantedTokens);
            }

            values.Add(id);
            await _storage.SetAsync(searchKey, values.ToString(), grantedToken.ExpiresIn); // 2. Store search key.

            return(true);
        }
Exemple #2
0
        public async Task <bool> AddAuthorizationCode(AuthorizationCode authorizationCode)
        {
            if (authorizationCode == null)
            {
                throw new ArgumentNullException(nameof(authorizationCode));
            }

            var authCode = await _storage.TryGetValueAsync <AuthorizationCode>(authorizationCode.Code);

            if (authCode != null)
            {
                return(false);
            }

            // TH : Externalize the date.
            await _storage.SetAsync(authorizationCode.Code, authorizationCode, 3600);

            return(true);
        }