2017-05-26 178 views
0

因此,我已經使用JWT令牌實現了Spring Oauth2安全性。Spring Oauth JWT - 刷新令牌

我可以得到JWT access_tokens但是refresh_token的用法是我不完全理解的。我可以使用refresh_token獲取新的access_token和新的refresh_token

當我想再次使用新的refresh_token時,我收到錯誤消息,說明此令牌無效。如果我用老refresh_token然後我得到的異常DuplicateKeyException, PreparedStatementCallback; SQL [insert into oauth_access_token (token_id, token, authentication_id, user_name, client_id, authentication, refresh_token) values (?, ?, ?, ?, ?, ?, ?)]; ERROR: duplicate key value violates unique constraint "oauth_access_token_pkey"

這是oauth_access_token表的DDL:

CREATE TABLE oauth_access_token (
    token_id varchar(510) NULL DEFAULT NULL::character varying, 
    token bytea NULL, 
    authentication_id varchar(510) NOT NULL, 
    user_name varchar(510) NULL DEFAULT NULL::character varying, 
    client_id varchar(510) NULL DEFAULT NULL::character varying, 
    authentication bytea NULL, 
    refresh_token varchar(510) NULL DEFAULT NULL::character varying, 
    CONSTRAINT oauth_access_token_pkey PRIMARY KEY (authentication_id) 
) 
WITH (
    OIDS=FALSE 
); 

如果我刪除約束oauth_access_token_pkey然後正常工作,但隨後的表包含N個令牌行,而不是1,並且因爲IncorrectResultSizeDataAccessException而不能發行新的代幣。

我應該怎麼做才能使刷新令牌工作?

回答

0

我用JwtTokenStore而不是JdbcTokenStore解決了這個「問題」。 JWT令牌應該是無狀態的,但是我將它們存儲在一個數據庫中,導致了這些問題。