Skip to content

Commit 76dc305

Browse files
author
LSZ
committed
1 parent 1abb1ff commit 76dc305

File tree

80 files changed

+2009
-727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2009
-727
lines changed

others/database/initial_db.ddl

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
-- ###############
22
-- create MySQL database , if need create, cancel the comment
33
-- ###############
4-
-- create database if not exists spring_oauth default character set utf8;
5-
-- use spring_oauth set default character = utf8;
4+
-- create database if not exists oauth2 default character set utf8;
5+
-- use oauth2 set default character = utf8;
66

77
-- ###############
8-
-- grant privileges to spring_oauth/spring_oauth
8+
-- grant privileges to oauth2/oauth2
99
-- ###############
10-
-- GRANT ALL PRIVILEGES ON spring_oauth.* TO spring_oauth@localhost IDENTIFIED BY "spring_oauth";
10+
-- GRANT ALL PRIVILEGES ON oauth2.* TO oauth2@localhost IDENTIFIED BY "oauth2";
1111

1212
-- ###############
1313
-- Domain: User
1414
-- ###############
1515
Drop table if exists user_;
16-
CREATE TABLE `user_` (
17-
`id` int(11) NOT NULL auto_increment,
18-
`guid` varchar(255) not null unique,
19-
`create_time` datetime ,
20-
`archived` tinyint(1) default '0',
21-
`email` varchar(255),
22-
`password` varchar(255) not null,
23-
`phone` varchar(255),
24-
`username` varchar(255) not null unique,
25-
`default_user` tinyint(1) default '0',
26-
`last_login_time` datetime ,
27-
PRIMARY KEY (`id`)
16+
CREATE TABLE user_ (
17+
id int(11) NOT NULL auto_increment,
18+
guid varchar(255) not null unique,
19+
create_time datetime ,
20+
archived tinyint(1) default '0',
21+
email varchar(255),
22+
password varchar(255) not null,
23+
phone varchar(255),
24+
username varchar(255) not null unique,
25+
default_user tinyint(1) default '0',
26+
last_login_time datetime ,
27+
PRIMARY KEY (id)
2828
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;
2929

3030

3131
-- ###############
3232
-- Domain: Privilege
3333
-- ###############
3434
Drop table if exists user_privilege;
35-
CREATE TABLE `user_privilege` (
36-
`user_id` int(11),
37-
`privilege` varchar(255)
35+
CREATE TABLE user_privilege (
36+
user_id int(11),
37+
privilege varchar(255),
38+
KEY user_id_index (user_id)
3839
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3940

others/database/oauth.ddl

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,62 @@
55
Drop table if exists oauth_client_details;
66
create table oauth_client_details (
77
client_id VARCHAR(255) PRIMARY KEY,
8-
resource_ids VARCHAR(256),
9-
client_secret VARCHAR(256),
10-
scope VARCHAR(256),
11-
authorized_grant_types VARCHAR(256),
12-
web_server_redirect_uri VARCHAR(256),
13-
authorities VARCHAR(256),
8+
resource_ids VARCHAR(255),
9+
client_secret VARCHAR(255),
10+
scope VARCHAR(255),
11+
authorized_grant_types VARCHAR(255),
12+
web_server_redirect_uri VARCHAR(255),
13+
authorities VARCHAR(255),
1414
access_token_validity INTEGER,
1515
refresh_token_validity INTEGER,
16-
additional_information VARCHAR(4096),
16+
additional_information TEXT,
1717
create_time timestamp default now(),
1818
archived tinyint(1) default '0',
19-
trusted tinyint(1) default '0'
20-
);
19+
trusted tinyint(1) default '0',
20+
autoapprove VARCHAR (255) default 'false'
21+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2122

22-
Drop table if exists oauth_client_token;
23-
create table oauth_client_token (
24-
create_time timestamp default now(),
25-
token_id VARCHAR(256),
26-
token BLOB,
27-
authentication_id VARCHAR(256),
28-
user_name VARCHAR(256),
29-
client_id VARCHAR(256)
30-
);
3123

3224
Drop table if exists oauth_access_token;
3325
create table oauth_access_token (
3426
create_time timestamp default now(),
35-
token_id VARCHAR(256),
27+
token_id VARCHAR(255),
3628
token BLOB,
37-
authentication_id VARCHAR(256),
38-
user_name VARCHAR(256),
39-
client_id VARCHAR(256),
29+
authentication_id VARCHAR(255),
30+
user_name VARCHAR(255),
31+
client_id VARCHAR(255),
4032
authentication BLOB,
41-
refresh_token VARCHAR(256)
42-
);
33+
refresh_token VARCHAR(255)
34+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
35+
4336

4437
Drop table if exists oauth_refresh_token;
4538
create table oauth_refresh_token (
4639
create_time timestamp default now(),
47-
token_id VARCHAR(256),
40+
token_id VARCHAR(255),
4841
token BLOB,
4942
authentication BLOB
50-
);
43+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
44+
5145

5246
Drop table if exists oauth_code;
5347
create table oauth_code (
5448
create_time timestamp default now(),
55-
code VARCHAR(256),
49+
code VARCHAR(255),
5650
authentication BLOB
57-
);
51+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
52+
53+
54+
55+
-- Add indexes
56+
create index token_id_index on oauth_access_token (token_id);
57+
create index authentication_id_index on oauth_access_token (authentication_id);
58+
create index user_name_index on oauth_access_token (user_name);
59+
create index client_id_index on oauth_access_token (client_id);
60+
create index refresh_token_index on oauth_access_token (refresh_token);
5861

62+
create index token_id_index on oauth_refresh_token (token_id);
5963

64+
create index code_index on oauth_code (code);
6065

6166

others/db_table_description.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h2>spring-oauth-server 数据库表说明</h2>
2222
</thead>
2323
<tbody>
2424
<tr>
25-
<td rowspan="14">oauth_client_details</td>
25+
<td rowspan="15">oauth_client_details</td>
2626
<td>client_id</td>
2727
<td>
2828
主键,必须唯一,不能为空.
@@ -188,6 +188,16 @@ <h2>spring-oauth-server 数据库表说明</h2>
188188
对该字段的具体使用请参考<code>OauthUserApprovalHandler.java</code>. (扩展字段)
189189
</td>
190190
</tr>
191+
<tr>
192+
<td>autoapprove</td>
193+
<td>
194+
设置用户是否自动Approval操作, 默认值为 'false', 可选值包括 'true','false', 'read','write'.
195+
<br/>
196+
该字段只适用于grant_type="authorization_code"的情况,当用户登录成功后,若该值为'true'或支持的scope值,则会跳过用户Approve的页面, 直接授权.
197+
<br/>
198+
该字段与 trusted 有类似的功能, 是 spring-security-oauth2 的 2.0 版本后添加的新属性.
199+
</td>
200+
</tr>
191201
<tr>
192202
<td colspan="2">
193203
<p class="text-info">
@@ -361,7 +371,7 @@ <h2>spring-oauth-server 数据库表说明</h2>
361371
</table>
362372

363373
<p class="text-muted">
364-
&copy; <a href="http://git.oschina.net/shengzhao/spring-oauth-server" target="_blank">spring-oauth-server</a>
374+
&copy; 2013 - 2015 <a href="http://git.oschina.net/shengzhao/spring-oauth-server" target="_blank">spring-oauth-server</a>
365375
</p>
366376
</div>
367377

others/how_to_use.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11

22

33
使用的主要技术与版本号
4-
*Spring (3.1.1.RELEASE)
5-
*Spring Security (3.1.0.RELEASE)
6-
*MyBatis (3.2.1)
7-
*spring-security-oauth2 (1.0.5.RELEASE)
4+
*Spring (4.1.6.RELEASE)
5+
*Spring Security (4.0.1.RELEASE)
6+
*spring-security-oauth2 (2.0.7.RELEASE)
87

98

109
如何使用?
11-
1.项目是Maven管理的, 需要本地安装maven(开发用的maven版本号为3.1.0), 还有MySql(开发用的mysql版本号为5.5)
10+
1.项目是Maven管理的, 需要本地安装maven(开发用的maven版本号为3.1.0), 还有MySql(开发用的mysql版本号为5.6)
1211

1312
2.下载(或clone)项目到本地
1413

@@ -17,7 +16,7 @@
1716

1817
4.修改spring-oauth-server.properties(位于src/resources目录)中的数据库连接信息(包括username, password等)
1918

20-
5.将本地项目导入到IDE(如Intellij IDEA)中,配置Tomcat(或类似的servelt运行服务器), 并启动Tomcat(默认端口为8080)
19+
5.将本地项目导入到IDE(如Intellij IDEA)中,配置Tomcat(或类似的servlet运行服务器), 并启动Tomcat(默认端口为8080)
2120
另: 也可通过maven package命令将项目编译为war文件(spring-oauth-server.war),
2221
将war放在Tomcat中并启动(注意: 这种方式需要将spring-oauth-server.properties加入到classpath中并正确配置数据库连接信息).
2322

others/oauth_test.txt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11

22
方式1:基于浏览器 (访问时后跳到登录页面,登录成功后跳转到redirect_uri指定的地址) [GET]
33
说明:只能使用admin或unity 账号登录才能有权限访问,若使用mobile账号登录将返回Access is denied
4-
http://localhost:8080/spring-oauth-server/oauth/authorize?client_id=unity-client&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2funity%2fdashboard.htm&response_type=code&scope=read
4+
http://localhost:8080/spring-oauth-server/oauth/authorize?client_id=unity-client&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2funity%2fdashboard&response_type=code&scope=read
55

66
说明: 由于mobile-client只支持password,refresh_token, 所以不管用哪个账号登录后都将返回Illegal action
7-
http://localhost:8080/spring-oauth-server/oauth/authorize?client_id=mobile-client&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2fm%2fdashboard.htm&response_type=code&scope=read
7+
http://localhost:8080/spring-oauth-server/oauth/authorize?client_id=mobile-client&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2fm%2fdashboard&response_type=code&scope=read
88

99

1010

1111

1212
响应的URL如:
1313
http://localhost:8080/spring-oauth-server/unity/dashboard.htm?code=zLl170
1414

15-
通过code换取access_token [GET]
16-
http://localhost:8080/spring-oauth-server/oauth/token?client_id=unity-client&client_secret=unity&grant_type=authorization_code&code=zLl170&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2funity%2fdashboard.htm
15+
通过code换取access_token [POST]
16+
http://localhost:8080/spring-oauth-server/oauth/token?client_id=unity-client&client_secret=unity&grant_type=authorization_code&code=zLl170&redirect_uri=http%3a%2f%2flocalhost%3a8080%2fspring-oauth-server%2funity%2fdashboard
1717

1818

19-
方式2:基于客户端 (注意参数中的username,password,对应用户的账号,密码) [GET]
19+
方式2:基于客户端 (注意参数中的username,password,对应用户的账号,密码) [POST]
2020
http://localhost:8080/spring-oauth-server/oauth/token?client_id=mobile-client&client_secret=mobile&grant_type=password&scope=read,write&username=mobile&password=mobile
2121

2222
说明:由于unity-client不支持password,所以若用unity-client通过password方式去授权,将返回invalid_grant
@@ -33,10 +33,28 @@ http://localhost:8080/spring-oauth-server/unity/dashboard.htm?access_token=3420d
3333

3434

3535

36-
刷新access_token [GET]
36+
刷新access_token [POST]
3737
http://localhost:8080/spring-oauth-server/oauth/token?client_id=mobile-client&client_secret=mobile&grant_type=refresh_token&refresh_token=b36f4978-a172-4aa8-af89-60f58abe3ba1
3838

3939

40+
Restful OAuth2 Test [POST]
41+
URL: /oauth2/rest_token
42+
ContentType: application/json
43+
44+
DEMO URL: http://localhost:8080/spring-oauth-server/oauth2/rest_token
45+
Request Body: {"grant_type":"client_credentials","scope":"read","client_id":"credentials","client_secret":"credentials","username":"user","password":"123"}
46+
47+
Response Body:
48+
{
49+
"access_token": "cd165ebc-562d-45df-8488-9f1ba947553e",
50+
"token_type": "bearer",
51+
"expires_in": 43193,
52+
"scope": "read"
53+
}
54+
55+
56+
57+
4058
更多的测试请访问
4159
http://git.oschina.net/mkk/spring-oauth-client
4260

75.1 KB
Loading

0 commit comments

Comments
 (0)