コード例 #1
0
        public override async Task StoreAsync(string key, RefreshToken value)
        {
            using (var con = Options.OpenConnection())
            {
                var token = await con.QueryFirstOrDefaultAsync <Token>("SELECT * FROM Tokens WHERE [Key] = @Key AND TokenType = @TokenType", new { Key = key, TokenType });

                if (token == null)
                {
                    token = new Token
                    {
                        Key       = key,
                        SubjectId = value.SubjectId,
                        ClientId  = value.ClientId,
                        TokenType = TokenType,
                        JsonCode  = ConvertToJson(value),
                        Expiry    = value.CreationTime.AddSeconds(value.LifeTime)
                    };
                    await
                    con.ExecuteAsync(
                        "INSERT INTO Tokens ([Key], SubjectId, ClientId, JsonCode, Expiry, TokenType) VALUES (@Key, @SubjectId, @ClientId, @JsonCode, @Expiry, @TokenType)",
                        token);
                }
                else
                {
                    token.JsonCode = ConvertToJson(value);
                    token.Expiry   = value.CreationTime.AddSeconds(value.LifeTime);
                    await
                    con.ExecuteAsync(
                        "UPDATE Tokens SET JsonCode=@JsonCode, Expiry=@Expiry WHERE [Key] = @Key, TokenType = @TokenType WHERE [Key]=@Key AND TokenType = @TokenType",
                        token);
                }
            }
        }
コード例 #2
0
        public override async Task StoreAsync(string key, AuthorizationCode code)
        {
            var token = new Token
            {
                Key       = key,
                SubjectId = code.SubjectId,
                ClientId  = code.ClientId,
                JsonCode  = ConvertToJson(code),
                Expiry    = DateTimeOffset.UtcNow.AddSeconds(code.Client.AuthorizationCodeLifetime),
                TokenType = TokenType
            };

            using (var con = Options.OpenConnection())
            {
                var r = await con.ExecuteAsync("INSERT INTO Tokens ([Key], SubjectId, ClientId, JsonCode, Expiry, TokenType) VALUES (@Key, @SubjectId, @ClientId, @JsonCode, @Expiry, @TokenType)", token);
            }
        }