Code Monkey home page Code Monkey logo

oauth2-server's Introduction

基于 Spring Security OAuth 的统一账号管理平台

preview confirm_access

技术栈:

  • Spring Boot
  • Spring Security
  • Spring Security OAuth2
  • Mybatis

环境依赖:

  • JRE1.8
  • Mysql5.7

启动流程:

  • 配置数据库
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: root
    url: jdbc:mysql://127.0.0.1:3306/auth?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
  • 配置微信登录

公众平台用于在微信内置浏览器打开时登录

开放平台用于在非微信环境下扫码登录

social:
  wx-mp: # 微信公众平台
    key: xxxx
    secret: xxx
  wx-open: # 微信开放平台
    key: xxxx
    secret: xxx
  • 配置图形验证码
captcha:
  enable: true # 启用
  base-str: '0123' #  随机字符
  length: 4  #  长度
  • 配置手机验证码(腾讯云)
sms:
  enable: true # 启用
  secretId: 'xxxx'
  secretKey: 'xxxx'
  appId: 'xxx'
  sign: 'xxx'
  templateId: 'xxx'
  • 配置页面
baseinfo:
  title: 浙江xxxx科技 # 标题
  beian: 浙ICP备xxxx号 # 备案号

编译 & 部署

mvn package
java -Dloader.path=./lib -jar auth-0.0.1.jar

接口

{xxx} 表示是一个参数变量

图形验证码

GET /captcha?key={timestamp} HTTP/1.1

手机验证码

GET /sms?phone={phone} HTTP/1.1

OAuth2 授权码

GET /oauth/authorize?client_id={client_id}&redirect_uri={redirect_uri}&response_type={response_type}&scope={scope}&state={state} HTTP/1.1

OAuth2 密码登录

扩展支持图形验证码,提高接口安全性

captchaKey: 图形验证码key, captchaCode: 图形验证码

POST /oauth/token HTTP/1.1
Authorization: Basic {Base64({client_id};{secret})}
Content-Type: application/x-www-form-urlencoded

grant_type=password&username={username}&password={password}&scope={scope}&captchaKey={captchaKey}&captchaCode={captchaCode}

OAuth2 授权码登录

POST /oauth/token HTTP/1.1
Authorization: Basic {Base64({client_id};{secret})}
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code={code}&scope={scope}

手机号,微信登录

if (type == 'sms')
    code = '手机验证码'
if (type == 'WX_MP')
    code = '微信公众平台授权码'
if (type == 'WX_OPEN')
    code = '微信开放平台授权码'
POST /oauth/token HTTP/1.1
Authorization: Basic {Base64({client_id};{secret})}
Content-Type: application/x-www-form-urlencoded

grant_type=social&type={type}&code={code}&scope={scope}

登录成功

{
    "access_token": "access_token",
    "token_type": "bearer",
    "expires_in": 43199,
    "scope": "read_user",
    "user_id": "11"
}

获取用户信息

GET /user_base HTTP/1.1
Authorization: Bearer {access_token}

scope!=all

{
  "msg": "SUCCESS",
  "code": "SUCCESS",
  "name": "xxxxx"
}

scope==all

{
  "msg": "SUCCESS",
  "code": "SUCCESS",
  "phone": "xxx",
  "name": "xxx",
  "email": "xxxx"
}

oauth2-server's People

Contributors

taoroot avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.