OAuth2接入
jmms内置了开箱即用的OAuth2
支持,通过简单的配置就可以接入符合标准的OAuth2
授权服务器。
环境准备
- 获取授权服务器地址,如:
http://oauth2.example.com
- 注册应用并获取信息,包括:
client_id
和client_secret
获取上面的信息请按您根据你接入的授权服务器提供的文档进行操作
配置OAuth2
修改app/config.json
配置文件,增加:
{
"oauth2": {
"enabled": true,
"server_url": "http://localhost:8088",
"client_id": "client1",
"client_secret": "secret1"
}
}
其中server_url
是一个简化配置,设置后会自动设置真正需要的四个配置属性:
authorize_url=${server_url}/oauth2/authorize
toekn_url="${server_url}/oauth2/token"
token_info_url="${server_url}/oauth2/tokeninfo
user_info_url="${server_url}/oauth2/userinfo
也可以分别单独配置四个属性:
config.json
{
"oauth2": {
"enabled": true,
"authorize_url": "http://localhost:8088/oauth2/authorize",
"token_url": "http://localhost:8088/oauth2/token",
"token_info_url": "http://localhost:8088/oauth2/tokeninfo",
"user_info_url": "http://localhost:8088/oauth2/userinfo",
"client_id": "client1",
"client_secret": "secret1"
}
}
接入Debug OAuth2 Server
(可选)
为了方便开发调试,可以接入一个简单的OAuth2
服务器(可选)。
- docker run:
$ docker run -p 8088:8080 leapframework/debug-auth-server
- git clone & maven run :
$ git clone https://github.com/leap-guides/gs-oauth2.git
$ cd gs-oauth2
$ mvn -Djetty.port=8088 jetty:run
两种方式运行成功后,授权服务器地址为:http://localhost:8088
。
debug-auth-server
内置了3个用户和3个client:
User : user1 pass1, user2, pass2, user3, pass3
Client: client1 secret1 , client2 secret2, client3 secret3
上一篇:安全指南
下一篇:内置OAuth2 Server