1. 程式人生 > 實用技巧 >Auth2.0-Client客戶端資料庫配置

Auth2.0-Client客戶端資料庫配置

Auth2.0-Client客戶端資料庫配置

Client客戶端資訊通常以HardCode方式放在inMemory裡面。本文我們將把ta放到資料庫裡面,以方便維護。

1.0 修改程式碼如下

 private final DataSource dataSource;

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.jdbc(dataSource);
    }

    @Bean
    public JdbcTokenStore tokenStore() {
        
return new JdbcTokenStore(dataSource); }

1.1 執行資料庫指令碼

schema.sql

DROP TABLE IF EXISTS oauth_client_details;

CREATE TABLE oauth_client_details
(
    client_id               VARCHAR(255) PRIMARY KEY,
    resource_ids            VARCHAR(255),
    client_secret           VARCHAR(255),
    scope                   
VARCHAR(255), authorized_grant_types VARCHAR(255), web_server_redirect_uri VARCHAR(255), authorities VARCHAR(255), access_token_validity INTEGER, refresh_token_validity INTEGER, additional_information VARCHAR(4096), autoapprove VARCHAR(255) );
DROP TABLE IF EXISTS oauth_client_token; CREATE TABLE oauth_client_token ( token_id VARCHAR(255), token LONG VARBINARY, authentication_id VARCHAR(255) PRIMARY KEY, user_name VARCHAR(255), client_id VARCHAR(255) ); DROP TABLE IF EXISTS oauth_access_token; CREATE TABLE oauth_access_token ( token_id VARCHAR(255), token LONG VARBINARY, authentication_id VARCHAR(255) PRIMARY KEY, user_name VARCHAR(255), client_id VARCHAR(255), authentication LONG VARBINARY, refresh_token VARCHAR(255) ); DROP TABLE IF EXISTS oauth_refresh_token; CREATE TABLE oauth_refresh_token ( token_id VARCHAR(255), token LONG VARBINARY, authentication LONG VARBINARY ); DROP TABLE IF EXISTS oauth_code; CREATE TABLE oauth_code ( code VARCHAR(255), authentication LONG VARBINARY ); DROP TABLE IF EXISTS oauth_approvals; CREATE TABLE oauth_approvals ( userid VARCHAR(255), clientid VARCHAR(255), scope VARCHAR(255), status VARCHAR(10), expiresat TIMESTAMP, lastmodifiedat TIMESTAMP );

data.sql

LOCK tables `oauth_client_details` WRITE; 
/*!40000 ALTER TABLE `oauth_client_details` DISABLE KEYS */ 
;INSERT INTO `oauth_client_details` VALUES 
            ( 
                        'clientApp', 
                        'resource_id', 
                        '$2a$10$R.QchD5KA5mrVYdbx4WwGunbEzcE8NUSxFz0qWhBSlhHCgJr5qLwq', 
                        'all', 
                        'password,authorization_code,client_credentials,refresh_token,implicit',
                        'http://baidu.com', 
                        'READ_ONLY_CLINT', 
                        NULL, 
                        NULL, 
                        '{}', 
                        '' 
            ); 

/*!40000 ALTER TABLE `oauth_client_details` ENABLE KEYS */ 
;UNLOCK tables;

2.0工作場景程式碼下載

序號內容
01 Vue+SpringBoot 檔案操作、上傳、預覽和刪除
02 Vue+Spring Data JPA+MySQL 增查改刪
03 React+Spring Data JPA+MySQL 增查改刪
04 Kotlin+Vue+Spring Data JPA+MySQL 增查改刪
05 Gmail+QQ郵箱傳送郵件
06 自定義Oauth2.0,Google和Github登入頁面
07 Oauth2 Password-Flow 授權。前後端分離,註冊和登入