• 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 授权。前后端分离,注册和登录

  • 相关阅读:
    windows常用命令行总结
    express安装
    MySQL去除外键关联关系
    c#实体转化
    C#之Clone
    mysql 将null转代为0(转)
    Mysql显示行号
    mysql存储过程游标加计划任务事件调度器
    mysql临时表
    Git学习笔记
  • 原文地址:https://www.cnblogs.com/JavaWeiBianCheng/p/13984048.html
Copyright © 2020-2023  润新知