content;
30 | private Long totalElements;
31 | }
32 |
--------------------------------------------------------------------------------
/oauth-server/src/main/java/com/pphh/oauth/vo/UserVO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 peipeihh
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * limitations under the License.
14 | */
15 | package com.pphh.oauth.vo;
16 |
17 | import lombok.Data;
18 |
19 | import java.util.Date;
20 |
21 | /**
22 | * UserVO
23 | *
24 | * @author huangyinhuang
25 | * @date 7/3/2018
26 | */
27 | @Data
28 | public class UserVO {
29 | Long id;
30 | String name;
31 | String email;
32 | Date lastVisitAt;
33 | Date insertTime;
34 | }
35 |
--------------------------------------------------------------------------------
/oauth-server/src/main/java/com/pphh/oauth/vo/ValidityVO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 peipeihh
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * limitations under the License.
14 | */
15 | package com.pphh.oauth.vo;
16 |
17 | import lombok.Data;
18 |
19 | /**
20 | * ValidityVO
21 | *
22 | * @author huangyinhuang
23 | * @date 7/3/2018
24 | */
25 | @Data
26 | public class ValidityVO {
27 | Boolean isValid;
28 |
29 | public ValidityVO() {
30 | this.isValid = Boolean.FALSE;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/oauth-server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # server
2 | server.port = 8090
3 |
4 | # disable spring security
5 | security.basic.enabled = false
6 | management.security.enabled = false
7 |
8 | # app settings
9 | spring.application.name = auth2-server
10 |
11 | # data source
12 | spring.datasource.url = jdbc:mysql://localhost:3306/simple_oauth?useUnicode=true&characterEncoding=utf-8&useSSL=false
13 | spring.datasource.username = root
14 | spring.datasource.password = root
15 | spring.datasource.initialize = true
16 | spring.jpa.show-sql = true
17 |
18 | # simple admin configuration
19 | # jwt check flag
20 | app.jwt.check.enable = true
21 | app.jwt.sign.secret = secret
22 | app.jwt.sign.issuer = oauth-server
23 | app.jwt.sign.expires = 168
24 | app.jwt.check.skip.uri = /api/account/login,/api/account/refreshPassword,/api/account/register,/oauth2/token,/oauth2/revoke,/oauth2/introspect,/oauth2/docker/token,/api/clients/introspect
25 |
26 | # oauth
27 | # auth code的过期时间:10分钟(10*60*1000=600000)
28 | # access token的过期时间:6小时(6*60*60*1000=21600000)
29 | # refresh token的过期时间:3天(3*24*60*60*1000=259200000)
30 | app.oauth.expiration.code = 600000
31 | app.oauth.expiration.access = 21600000
32 | app.oauth.expiration.refreshtoken = 259200000
33 |
34 | # scheduler,其中timeout一般配置为fixedRate的三倍
35 | # Token软删除:每隔5分钟
36 | # Token硬删除:每天下午13点05分
37 | app.scheduler.enable = true
38 | app.scheduler.token.removal = 0 0/5 * * * ?
39 | app.scheduler.token.clean = 0 5 13 * * ?
40 |
41 | # docker registry with fixed client id/secret
42 | app.docker.registry.clientId = docker
43 | app.docker.registry.clientSecret = docker_secret
44 |
--------------------------------------------------------------------------------
/sample/demo-front-jquery/README.md:
--------------------------------------------------------------------------------
1 |
2 | ## 1. 简介
3 |
4 | 这是一个演示项目,使用纯前端技术栈(html+jquery+css),对接Simple-OAuth所提供的oauth 2.0 implicit grant授权方式,实现用户登录功能。
5 |
6 | ## 2. 项目的结构和构建
7 |
8 | ```
9 | - README.md 使用说明文档
10 | - package.json NPM构建配置文件
11 | - app.js express服务器启动配置文件
12 | + src
13 | - index.html 前端应用主页面
14 | - callback.html 登录后回调页面
15 | ```
16 |
17 | #### 2.1 安装node并配置npm源
18 |
19 | 登录node官方网站安装node 3.10.8+。
20 |
21 | 配置npm源为淘宝源
22 |
23 | ```
24 | npm set registry "https://registry.npm.taobao.org/"
25 | ```
26 |
27 | 配置后可以通过npm config list查看。
28 |
29 | #### 2.2 前端项目构建运行命令
30 |
31 | 构建文件:./package.json
32 |
33 | 下载依赖包:npm install,执行成功后将会把express依赖包下载到/node_modules目录。
34 |
35 | 运行命令:node app.js,运行成功后可以通过[http://localhost:9001](http://localhost:9001)访问应用
36 |
37 | 注:应用的启动端口在./app.js文件中进行配置。
38 |
39 | ## 3. 演示
40 |
41 | 1. 准备工作
42 | - 根据oauth-server项目的README文档,启动simple oauth后端web服务。
43 | - 根据oauth-front项目的README文档,启动simple oauth前端web服务。
44 | - 若以项目缺省配置,simple oauth前端和后端分别启动在如下两个地址,
45 | ```
46 | 前端服务 http://localhost
47 | 后端服务 http://localhost:8090
48 | ```
49 | - 本演示项目将根据上面的两个地址进行授权登录跳转。
50 |
51 | 2. 注册应用
52 | - 请登录oauth前端页面,应该能看到auth server已经注册一个缺省的demo应用。
53 | * 应用查看列表:[http://localhost/#/dev/myclient](http://localhost/#/dev/myclient)
54 |
55 | - 若没有发现demo应用,可以手动注册应用,
56 | * client id = demo
57 | * 重定向返回地址为:.* (其含义为simple oauth接受demo client指定的任何返回地址)
58 |
59 | 3. 启动当前演示项目
60 | - 执行前端应用运行命令:node app.js
61 | - 打开浏览器,访问前端应用地址:http://localhost:9001
62 | - 点击登录按钮,将跳转到simple oauth的授权界面:http://localhost/#/authorize,点击同意按钮。
63 | * 注:若simple oauth没有登录,则需要先登录,再点击同意授权按钮,登录账号缺省为admin/admin,详情请查看simple auth项目readme文件。
64 | - 若一切正常,simple oauth将跳转回当前前端演示应用地址,并完成登录,显示登录账号。
65 |
--------------------------------------------------------------------------------
/sample/demo-front-jquery/app.js:
--------------------------------------------------------------------------------
1 | let express = require('express');
2 | let app = express();
3 | app.use(express.static('src', {'index': 'index.html'}));
4 |
5 | // app.get('/api/hello', function (req, res) {
6 | // res.send('Hello World!');
7 | // });
8 |
9 | app.listen(9001);
10 | console.log("server is started, please open following url in the browser: ");
11 | console.log("http://localhost:9001");
--------------------------------------------------------------------------------
/sample/demo-front-jquery/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "demo-front-jquery",
3 | "version": "1.0.0",
4 | "description": "this is a simple web front project with jquery, interact with oauth 2.0 - implicit grant mode.",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "pphh",
10 | "license": "Apache License 2.0",
11 | "dependencies": {
12 | "express": "^4.15.3"
13 | }
14 | }
--------------------------------------------------------------------------------
/sample/demo-front-jquery/src/callback.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 登录回调页面
6 |
7 |
8 |
9 | 登录回调页面
10 | 登录中......
11 | 回到首页
12 |
13 |
14 |
15 |
16 |
17 |
18 |
39 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "es2015",
4 | "stage-2"
5 | ],
6 | "plugins": [
7 | "transform-runtime",
8 | "transform-vue-jsx"
9 | ],
10 | "comments": true
11 | }
12 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/.postcssrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "plugins": {
3 | "autoprefixer": {}
4 | }
5 | };
6 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "front-vue",
3 | "version": "1.0.0",
4 | "description": "this is a simple demo of oauth.",
5 | "main": "webpack.config.js",
6 | "scripts": {
7 | "dev": "webpack-dev-server --inline --hot --env.dev",
8 | "build": "webpack -p --progress --hide-modules"
9 | },
10 | "repository": {
11 | "type": "git",
12 | "url": "git@gitee.com:pphh/simple-oauth2.git"
13 | },
14 | "keywords": [
15 | "auth 2.0"
16 | ],
17 | "author": "pphh",
18 | "license": "Apache License 2.0",
19 | "dependencies": {
20 | "axios": "^0.16.2",
21 | "echarts": "^3.5.0",
22 | "element-ui": "^2.0.9",
23 | "jwt-decode": "^2.1.0",
24 | "vue": "^2.5.2",
25 | "vue-router": "^2.0.0",
26 | "vuex": "^2.3.1"
27 | },
28 | "devDependencies": {
29 | "babel-core": "^6.0.0",
30 | "babel-loader": "^6.0.0",
31 | "babel-plugin-component": "^0.9.1",
32 | "babel-preset-env": "^1.6.1",
33 | "babel-preset-es2015": "^6.24.1",
34 | "babel-preset-stage-2": "^6.24.1",
35 | "babel-preset-vue-app": "^1.2.0",
36 | "cross-env": "^1.0.6",
37 | "css-loader": "^0.23.1",
38 | "file-loader": "^0.8.5",
39 | "html-webpack-plugin": "^2.24.1",
40 | "jsonwebtoken": "^7.3.0",
41 | "postcss-loader": "^1.3.3",
42 | "request": "^2.79.0",
43 | "style-loader": "^0.13.1",
44 | "uglifyjs-webpack-plugin": "^0.4.6",
45 | "url-loader": "^0.5.8",
46 | "vue-loader": "^9.8.0",
47 | "vue-style-loader": "^2.0.0",
48 | "webpack": "^2.4.5",
49 | "webpack-dev-server": "^2.4.5"
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/api/index.js:
--------------------------------------------------------------------------------
1 | import axios from 'axios'
2 | import service from './service'
3 |
4 | axios.defaults.timeout = 60000;
5 | axios.defaults.headers.common['Content-Type'] = 'application/json';
6 | axios.defaults.headers.post['Content-Type'] = 'application/json';
7 | axios.defaults.headers.put['Content-Type'] = 'application/json';
8 |
9 | export const api = service;
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/api/restApi.js:
--------------------------------------------------------------------------------
1 | import axios from 'axios'
2 |
3 | export default {
4 |
5 | doGetRequest(url){
6 | return axios.get(url)
7 | .then((response) => Promise.resolve(response))
8 | .catch((error) => Promise.reject(error))
9 | },
10 | doDeleteRequest(url){
11 | return axios.delete(url)
12 | .then((response) => Promise.resolve(response))
13 | .catch((error) => Promise.reject(error))
14 | },
15 | doPutRequest(url, data){
16 | if (typeof(data) == "object") {
17 | data = JSON.stringify(data);
18 | }
19 | return axios.put(url, data)
20 | .then((response) => Promise.resolve(response))
21 | .catch((error) => Promise.reject(error))
22 | },
23 | doPostRequest(url, data){
24 | if (typeof(data) == "object") {
25 | data = JSON.stringify(data);
26 | }
27 | return axios.post(url, data)
28 | .then((response) => Promise.resolve(response))
29 | .catch((error) => Promise.reject(error))
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/api/service/authService.js:
--------------------------------------------------------------------------------
1 | import restApi from '../restApi'
2 |
3 | export default {
4 | fetchToken(request = {}) {
5 | let url = 'api/oauth2/accessToken?code=' + request.code;
6 | return restApi.doGetRequest(url);
7 | },
8 | refreshToken(request = {}) {
9 | let url = 'api/oauth2/refreshToken?refresh_token=' + request.refresh_token;
10 | return restApi.doGetRequest(url);
11 | },
12 | revokeToken(request = {}) {
13 | let url = 'api/oauth2/revokeToken?token=' + request.token;
14 | return restApi.doGetRequest(url);
15 | },
16 | fetchLoginUrl(request = {}) {
17 | let url = null;
18 | if (request != null && request.callback != null) {
19 | url = 'api/oauth2/redirectUrl?callback=' + encodeURIComponent(request.callback);
20 | } else {
21 | url = 'api/oauth2/redirectUrl';
22 | }
23 | return restApi.doGetRequest(url);
24 | },
25 | fetchTestData(request = {}) {
26 | let url = 'api/test/fetch';
27 | return restApi.doGetRequest(url);
28 | },
29 | updateTestData(request = {}) {
30 | let url = 'api/test/update?newData=' + request.newData;
31 | return restApi.doPostRequest(url);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/api/service/index.js:
--------------------------------------------------------------------------------
1 | import authService from './authService'
2 |
3 | export default {
4 | authService
5 | }
6 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/assets/common.css:
--------------------------------------------------------------------------------
1 | html, body {
2 | height: 100%;
3 | }
4 |
5 | body {
6 | margin: 0px;
7 | }
8 |
9 | #app {
10 | height: 100%;
11 | }
12 |
13 | .user-info .user-logo {
14 | background: url("../assets/img/dog.jpg");
15 | }
16 |
17 | .login-wrapper .login-fail-img {
18 | background: url("../assets/img/fail_login.jpg");
19 | }
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/assets/img/dog.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peipeihh/simple-oauth2/5cbbde9cdfd9fd2e75d1b3f087ab7cde02abed66/sample/demo-front-vue-spring-boot-web/front-vue/src/assets/img/dog.jpg
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/assets/img/fail_login.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peipeihh/simple-oauth2/5cbbde9cdfd9fd2e75d1b3f087ab7cde02abed66/sample/demo-front-vue-spring-boot-web/front-vue/src/assets/img/fail_login.jpg
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/components/Footer.vue:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/components/SiderBar.vue:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
36 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Hello, This is simple demo how to connect with simple oauth.
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 |
3 | import VueRouter from 'vue-router'
4 | Vue.use(VueRouter);
5 |
6 | import ElementUI from 'element-ui'
7 | import 'element-ui/lib/theme-chalk/index.css'
8 | Vue.use(ElementUI);
9 |
10 | import axios from 'axios'
11 | import router from './router'
12 | import store from './store'
13 | import jwtTokenUtil from "./utils/jwtTokenUtil";
14 |
15 |
16 | /**
17 | * enable axios ajax call in the vue component
18 | * please see the usage example in the ./pages/pages/demo/Ajax.vue
19 | * @type {AxiosStatic}
20 | */
21 | Vue.prototype.$http = axios;
22 |
23 | /**
24 | * enable the development mode
25 | * @type {boolean}
26 | */
27 | Vue.config.devtools = process.env.NODE_ENV === 'development';
28 |
29 | // http request 拦截器
30 | axios.interceptors.request.use(
31 | config => {
32 | let jwtToken = jwtTokenUtil.readAccess();
33 | // 给http请求的header加上jwt-token
34 | config.headers['jwt-token'] = jwtToken;
35 | return config;
36 | },
37 | error => {
38 | return Promise.reject(error);
39 | }
40 | );
41 |
42 | /**
43 | * initialize the vue app with vuex store and vue router
44 | */
45 | new Vue({
46 | store,
47 | router,
48 | }).$mount('#app');
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/pages/Blank.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
GET
4 |
POST
5 |
{{testData}}
6 |
7 |
8 |
9 |
27 |
28 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/pages/Layout.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
45 |
46 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/router/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Router from 'vue-router'
3 |
4 | Vue.use(Router);
5 |
6 |
7 | import Layout from '../pages/Layout.vue'
8 | import BlankPage from '../pages/Blank.vue'
9 | import Login from '../pages/Login.vue'
10 |
11 |
12 | export default new Router({
13 | mode: 'hash', // mode option: 1. hash (default), 2. history
14 | routes: [{
15 | path: '',
16 | component: Layout,
17 | children: [{
18 | path: '',
19 | name: 'blank',
20 | component: BlankPage
21 | }]
22 | }, {
23 | path: '/login',
24 | name: 'Login',
25 | component: Login,
26 | }],
27 | linkActiveClass: 'active'
28 | })
29 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/store/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Vuex from 'vuex'
3 | import oauth from './model/oauth'
4 | Vue.use(Vuex);
5 |
6 | /**
7 | * detect current environment and set the debug configuration for vue store
8 | */
9 | const debug_mode = process.env.NODE_ENV !== 'production';
10 |
11 | /**
12 | * initialize the vuex store with actions/getters/modules
13 | */
14 | export default new Vuex.Store({
15 | modules: {
16 | oauth
17 | },
18 | strict: debug_mode
19 | })
20 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/utils/jwtTokenUtil.js:
--------------------------------------------------------------------------------
1 | export default {
2 |
3 | saveAccess(token){
4 | localStorage.setItem("access-token", token);
5 | },
6 |
7 | readAccess(){
8 | return localStorage.getItem("access-token");
9 | },
10 |
11 | saveRefresh(token){
12 | localStorage.setItem("refresh-token", token);
13 | },
14 |
15 | readRefresh(){
16 | return localStorage.getItem("refresh-token");
17 | },
18 |
19 | clear(){
20 | localStorage.removeItem("access-token");
21 | localStorage.removeItem("refresh-token");
22 | },
23 |
24 | }
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/utils/lastVisitUtil.js:
--------------------------------------------------------------------------------
1 |
2 | export default {
3 |
4 | save(url){
5 | localStorage.setItem("last-visited", url);
6 | },
7 |
8 | read(){
9 | return localStorage.getItem("last-visited");
10 | },
11 |
12 | clear(){
13 | localStorage.removeItem("last-visited");
14 | }
15 |
16 | }
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/front-vue/src/vendor.js:
--------------------------------------------------------------------------------
1 | /**
2 | * list all 3rd party modules here, which will be packaged as vendor.js
3 | */
4 |
5 | import Vue from 'vue'
6 | import ElementUI from 'element-ui'
7 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | oauth-sample
7 | com.pphh.demo
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | demo-front-vue-spring-boot-web
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 | com.pphh.demo
21 | oauth-spring-boot-websupport
22 |
23 |
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-maven-plugin
30 | ${springboot.version}
31 |
32 |
33 |
34 | repackage
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/src/main/java/com/pphh/oauth/sample/Application.java:
--------------------------------------------------------------------------------
1 | package com.pphh.oauth.sample;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * Please add description here.
8 | *
9 | * @author huangyinhuang
10 | * @date 8/2/2018
11 | */
12 | @SpringBootApplication
13 | public class Application {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(Application.class, args);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/src/main/java/com/pphh/oauth/sample/AutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.pphh.oauth.sample;
2 |
3 | import com.pphh.oauth.client.webcontroller.OAuthClientController;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | /**
8 | * Please add description here.
9 | *
10 | * @author huangyinhuang
11 | * @date 8/2/2018
12 | */
13 | @Configuration
14 | public class AutoConfiguration {
15 |
16 | @Bean
17 | public OAuthClientController oauthLoginController() {
18 | return new OAuthClientController();
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/src/main/java/com/pphh/oauth/sample/TestController.java:
--------------------------------------------------------------------------------
1 | package com.pphh.oauth.sample;
2 |
3 | import com.pphh.oauth.core.response.MessageType;
4 | import com.pphh.oauth.core.response.Response;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 | import org.springframework.web.bind.annotation.RequestParam;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | /**
11 | * Please add description here.
12 | *
13 | * @author huangyinhuang
14 | * @date 8/2/2018
15 | */
16 | @RestController
17 | @RequestMapping("/api/test")
18 | public class TestController {
19 |
20 | @RequestMapping(value = "/fetch", method = RequestMethod.GET)
21 | public Response getTest() {
22 | return Response.mark(MessageType.SUCCESS, "test");
23 | }
24 |
25 | @RequestMapping(value = "/update", method = RequestMethod.POST)
26 | public Response updateTest(@RequestParam(value = "newData") String newData) {
27 | return Response.mark(MessageType.SUCCESS, newData);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/sample/demo-front-vue-spring-boot-web/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # server configuration
2 | server.port = 9007
3 |
4 | # oauth spring client settings
5 | oauth.server.url = http://localhost
6 |
7 | # oauth spring filter settings
8 | oauth.spring.filter.type = all-check-by-skip
9 | oauth.spring.filter.token.store.type = header
10 | oauth.spring.filter.token.name = jwt-token
11 | oauth.spring.filter.special.urls = GET&.*
12 |
13 | # oauth spring support settings
14 | oauth.client.id = demo
15 | oauth.client.callback = http://localhost:9006/#/login
16 | oauth.client.authorization = Basic ZGVtbzo1MGROOTI=
--------------------------------------------------------------------------------
/sample/demo-front-vue/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "es2015",
4 | "stage-2"
5 | ],
6 | "plugins": [
7 | "transform-runtime",
8 | "transform-vue-jsx"
9 | ],
10 | "comments": true
11 | }
12 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/.postcssrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "plugins": {
3 | "autoprefixer": {}
4 | }
5 | };
6 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/README.md:
--------------------------------------------------------------------------------
1 |
2 | ## 1. 简介
3 |
4 | 这是一个演示项目,使用前端vue框架(vue 2.0 + vue.router + vuex),对接Simple OAuth所提供的oauth 2.0 authorization grant授权方式,实现用户登录功能。
5 |
6 | ## 2. 项目的结构和构建
7 |
8 | ```
9 | - README.md 使用说明文档
10 | - package.json NPM构建配置文件
11 | - webpack.config.js 前端webpack打包配置
12 | + src
13 | - index.html 前端应用主页面
14 | - main.js 前端应用入口
15 | + api 对后端API的接口调用
16 | + assets 静态资源文件
17 | + components VUE组件
18 | + pages 页面组件
19 | + router 前端路由
20 | + store 数据模型层
21 | ```
22 |
23 | #### 2.1 安装node并配置npm源
24 |
25 | 登录node官方网站安装node 3.10.8+。
26 |
27 | 配置npm源为淘宝源
28 |
29 | ```
30 | npm set registry "https://registry.npm.taobao.org/"
31 | ```
32 |
33 | 配置后可以通过npm config list查看。
34 |
35 | #### 2.2 前端项目构建运行命令
36 |
37 | 构建文件:./package.json
38 |
39 | 下载依赖包:npm install,执行成功后将会把express依赖包下载到/node_modules目录。
40 |
41 | 构建命令:npm run build,构建成功后将会生成./dist目录。
42 |
43 | 运行命令:npm run dev,运行成功后可以通过[http://localhost:9002](http://localhost:9002)访问应用
44 |
45 | 注:应用的启动端口在./webpack.config.js文件中devServer.port选项所配置。
46 |
47 | ## 3. 演示
48 |
49 | 1. 准备工作
50 | - 根据oauth-server项目的README文档,启动simple oauth后端web服务。
51 | - 根据oauth-front项目的README文档,启动simple oauth前端web服务。
52 | - 若以项目缺省配置,simple oauth前端和后端分别启动在如下两个地址,
53 | ```
54 | 前端服务 http://localhost
55 | 后端服务 http://localhost:8090
56 | ```
57 | - 本演示项目将根据上面的两个地址进行授权登录跳转。
58 |
59 | 2. 注册应用
60 | - 请登录oauth前端页面,应该能看到auth server已经注册一个缺省的demo应用。
61 | * 应用查看列表:[http://localhost/#/dev/myclient](http://localhost/#/dev/myclient)
62 |
63 | - 若没有发现demo应用,可以手动注册应用,
64 | * client id = demo
65 | * 重定向返回地址 = .* (其含义为simple oauth接受demo client指定的任何返回地址)
66 | * 注册成功后,更新./webpack.config.js中下面的配置,
67 | ```
68 | 'authorization': 'Basic ZGVtbzo1MGROOTI=',
69 | ```
70 |
71 | 3. 启动当前演示项目
72 | - 执行前端应用运行命令:npm run dev
73 | - 打开浏览器,访问前端应用地址:http://localhost:9002
74 | - 点击登录按钮,将跳转到simple oauth的授权界面:http://localhost/#/authorize,点击同意按钮。
75 | * 注:若simple oauth没有登录,则需要先登录,再点击同意授权按钮,登录账号缺省为admin/admin,详情请查看simple auth项目readme文件。
76 | - 若一切正常,simple oauth将跳转回当前前端演示应用地址,并完成登录,显示登录账号。
77 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "front-vue",
3 | "version": "1.0.0",
4 | "description": "this is a simple demo of oauth.",
5 | "main": "webpack.config.js",
6 | "scripts": {
7 | "dev": "webpack-dev-server --inline --hot --env.dev",
8 | "build": "webpack -p --progress --hide-modules"
9 | },
10 | "repository": {
11 | "type": "git",
12 | "url": "git@gitee.com:pphh/simple-oauth2.git"
13 | },
14 | "keywords": [
15 | "auth 2.0"
16 | ],
17 | "author": "pphh",
18 | "license": "Apache License 2.0",
19 | "dependencies": {
20 | "axios": "^0.16.2",
21 | "echarts": "^3.5.0",
22 | "element-ui": "^2.0.9",
23 | "jwt-decode": "^2.1.0",
24 | "vue": "^2.5.2",
25 | "vue-router": "^2.0.0",
26 | "vuex": "^2.3.1"
27 | },
28 | "devDependencies": {
29 | "babel-core": "^6.0.0",
30 | "babel-loader": "^6.0.0",
31 | "babel-plugin-component": "^0.9.1",
32 | "babel-preset-env": "^1.6.1",
33 | "babel-preset-es2015": "^6.24.1",
34 | "babel-preset-stage-2": "^6.24.1",
35 | "babel-preset-vue-app": "^1.2.0",
36 | "cross-env": "^1.0.6",
37 | "css-loader": "^0.23.1",
38 | "file-loader": "^0.8.5",
39 | "html-webpack-plugin": "^2.24.1",
40 | "jsonwebtoken": "^7.3.0",
41 | "postcss-loader": "^1.3.3",
42 | "request": "^2.79.0",
43 | "style-loader": "^0.13.1",
44 | "uglifyjs-webpack-plugin": "^0.4.6",
45 | "url-loader": "^0.5.8",
46 | "vue-loader": "^9.8.0",
47 | "vue-style-loader": "^2.0.0",
48 | "webpack": "^2.4.5",
49 | "webpack-dev-server": "^2.4.5"
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/api/index.js:
--------------------------------------------------------------------------------
1 | import axios from 'axios'
2 | import service from './service'
3 |
4 | axios.defaults.timeout = 60000;
5 | axios.defaults.headers.common['Content-Type'] = 'application/json';
6 | axios.defaults.headers.post['Content-Type'] = 'application/json';
7 | axios.defaults.headers.put['Content-Type'] = 'application/json';
8 |
9 | export const api = service;
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/api/restApi.js:
--------------------------------------------------------------------------------
1 | import axios from 'axios'
2 |
3 | export default {
4 |
5 | doGetRequest(url){
6 | return axios.get(url)
7 | .then((response) => Promise.resolve(response))
8 | .catch((error) => Promise.reject(error))
9 | },
10 | doDeleteRequest(url){
11 | return axios.delete(url)
12 | .then((response) => Promise.resolve(response))
13 | .catch((error) => Promise.reject(error))
14 | },
15 | doPutRequest(url, data){
16 | if (typeof(data) == "object") {
17 | data = JSON.stringify(data);
18 | }
19 | return axios.put(url, data)
20 | .then((response) => Promise.resolve(response))
21 | .catch((error) => Promise.reject(error))
22 | },
23 | doPostRequest(url, data){
24 | if (typeof(data) == "object") {
25 | data = JSON.stringify(data);
26 | }
27 | return axios.post(url, data)
28 | .then((response) => Promise.resolve(response))
29 | .catch((error) => Promise.reject(error))
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/api/service/authService.js:
--------------------------------------------------------------------------------
1 | import restApi from '../restApi'
2 |
3 | export default {
4 | fetchToken(request = {}) {
5 | let url = 'api/oauth2/accessToken?code=' + request.code;
6 | return restApi.doGetRequest(url);
7 | },
8 | refreshToken(request = {}) {
9 | let url = 'api/oauth2/refreshToken?refresh_token=' + request.refresh_token;
10 | return restApi.doGetRequest(url);
11 | },
12 | revokeToken(request = {}) {
13 | let url = 'api/oauth2/revokeToken?token=' + request.token;
14 | return restApi.doGetRequest(url);
15 | },
16 | fetchLoginUrl(request = {}) {
17 | let url = null;
18 | if (request != null && request.callback != null) {
19 | url = 'api/oauth2/redirectUrl?callback=' + encodeURIComponent(request.callback);
20 | } else {
21 | url = 'api/oauth2/redirectUrl';
22 | }
23 | return restApi.doGetRequest(url);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/api/service/index.js:
--------------------------------------------------------------------------------
1 | import authService from './authService'
2 |
3 | export default {
4 | authService
5 | }
6 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/assets/common.css:
--------------------------------------------------------------------------------
1 | html, body {
2 | height: 100%;
3 | }
4 |
5 | body {
6 | margin: 0px;
7 | }
8 |
9 | #app {
10 | height: 100%;
11 | }
12 |
13 | .user-info .user-logo {
14 | background: url("../assets/img/dog.jpg");
15 | }
16 |
17 | .login-wrapper .login-fail-img {
18 | background: url("../assets/img/fail_login.jpg");
19 | }
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/assets/img/dog.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peipeihh/simple-oauth2/5cbbde9cdfd9fd2e75d1b3f087ab7cde02abed66/sample/demo-front-vue/src/assets/img/dog.jpg
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/assets/img/fail_login.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peipeihh/simple-oauth2/5cbbde9cdfd9fd2e75d1b3f087ab7cde02abed66/sample/demo-front-vue/src/assets/img/fail_login.jpg
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/components/Footer.vue:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/components/SiderBar.vue:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
36 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Hello, This is simple demo how to connect with simple oauth.
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 |
3 | import VueRouter from 'vue-router'
4 | Vue.use(VueRouter);
5 |
6 | import ElementUI from 'element-ui'
7 | import 'element-ui/lib/theme-chalk/index.css'
8 | Vue.use(ElementUI);
9 |
10 | import axios from 'axios'
11 | import router from './router'
12 | import store from './store'
13 | import jwtTokenUtil from "./utils/jwtTokenUtil";
14 |
15 |
16 | /**
17 | * enable axios ajax call in the vue component
18 | * please see the usage example in the ./pages/pages/demo/Ajax.vue
19 | * @type {AxiosStatic}
20 | */
21 | Vue.prototype.$http = axios;
22 |
23 | /**
24 | * enable the development mode
25 | * @type {boolean}
26 | */
27 | Vue.config.devtools = process.env.NODE_ENV === 'development';
28 |
29 | // http request 拦截器
30 | axios.interceptors.request.use(
31 | config => {
32 | let jwtToken = jwtTokenUtil.readAccess();
33 | // 给http请求的header加上jwt-token
34 | config.headers['jwt-token'] = jwtToken;
35 | return config;
36 | },
37 | error => {
38 | return Promise.reject(error);
39 | }
40 | );
41 |
42 | /**
43 | * initialize the vue app with vuex store and vue router
44 | */
45 | new Vue({
46 | store,
47 | router,
48 | }).$mount('#app');
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/pages/Blank.vue:
--------------------------------------------------------------------------------
1 |
2 | Hello, this is a blank page.
3 |
4 |
5 |
8 |
9 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/pages/Layout.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
45 |
46 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/router/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Router from 'vue-router'
3 |
4 | Vue.use(Router);
5 |
6 |
7 | import Layout from '../pages/Layout.vue'
8 | import BlankPage from '../pages/Blank.vue'
9 | import Login from '../pages/Login.vue'
10 |
11 |
12 | export default new Router({
13 | mode: 'hash', // mode option: 1. hash (default), 2. history
14 | routes: [{
15 | path: '',
16 | component: Layout,
17 | children: [{
18 | path: '',
19 | name: 'blank',
20 | component: BlankPage
21 | }]
22 | }, {
23 | path: '/login',
24 | name: 'Login',
25 | component: Login,
26 | }],
27 | linkActiveClass: 'active'
28 | })
29 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/store/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Vuex from 'vuex'
3 | import oauth from './model/oauth'
4 | Vue.use(Vuex);
5 |
6 | /**
7 | * detect current environment and set the debug configuration for vue store
8 | */
9 | const debug_mode = process.env.NODE_ENV !== 'production';
10 |
11 | /**
12 | * initialize the vuex store with actions/getters/modules
13 | */
14 | export default new Vuex.Store({
15 | modules: {
16 | oauth
17 | },
18 | strict: debug_mode
19 | })
20 |
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/utils/jwtTokenUtil.js:
--------------------------------------------------------------------------------
1 | export default {
2 |
3 | saveAccess(token){
4 | localStorage.setItem("access-token", token);
5 | },
6 |
7 | readAccess(){
8 | return localStorage.getItem("access-token");
9 | },
10 |
11 | saveRefresh(token){
12 | localStorage.setItem("refresh-token", token);
13 | },
14 |
15 | readRefresh(){
16 | return localStorage.getItem("refresh-token");
17 | },
18 |
19 | clear(){
20 | localStorage.removeItem("access-token");
21 | localStorage.removeItem("refresh-token");
22 | },
23 |
24 | }
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/utils/lastVisitUtil.js:
--------------------------------------------------------------------------------
1 |
2 | export default {
3 |
4 | save(url){
5 | localStorage.setItem("last-visited", url);
6 | },
7 |
8 | read(){
9 | return localStorage.getItem("last-visited");
10 | },
11 |
12 | clear(){
13 | localStorage.removeItem("last-visited");
14 | }
15 |
16 | }
--------------------------------------------------------------------------------
/sample/demo-front-vue/src/vendor.js:
--------------------------------------------------------------------------------
1 | /**
2 | * list all 3rd party modules here, which will be packaged as vendor.js
3 | */
4 |
5 | import Vue from 'vue'
6 | import ElementUI from 'element-ui'
7 |
--------------------------------------------------------------------------------
/sample/demo-spring-boot-web/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | oauth-sample
7 | com.pphh.demo
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | demo-spring-boot-web
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 | com.pphh.demo
21 | oauth-spring-boot-autoconfigure
22 |
23 |
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-maven-plugin
30 | ${springboot.version}
31 |
32 |
33 |
34 | repackage
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/sample/demo-spring-boot-web/src/main/java/com/pphh/oauth/sample/AppProperties.java:
--------------------------------------------------------------------------------
1 | package com.pphh.oauth.sample;
2 |
3 | /**
4 | * Please add description here.
5 | *
6 | * @author huangyinhuang
7 | * @date 8/1/2018
8 | */
9 | public class AppProperties {
10 |
11 | public static String cookieDomain = "localhost";
12 | public static String cookiePath = "/";
13 | public static boolean cookieSecure = false;
14 | public static int cookieExpiry = 3600;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/sample/demo-spring-boot-web/src/main/java/com/pphh/oauth/sample/UserCredential.java:
--------------------------------------------------------------------------------
1 | package com.pphh.oauth.sample;
2 |
3 | /**
4 | * Please add description here.
5 | *
6 | * @author huangyinhuang
7 | * @date 8/1/2018
8 | */
9 | public class UserCredential {
10 |
11 | String userName;
12 | String userPwd;
13 |
14 | public String getUserName() {
15 | return userName;
16 | }
17 |
18 | public void setUserName(String userName) {
19 | this.userName = userName;
20 | }
21 |
22 | public String getUserPwd() {
23 | return userPwd;
24 | }
25 |
26 | public void setUserPwd(String userPwd) {
27 | this.userPwd = userPwd;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/sample/demo-spring-boot-web/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port = 9005
2 |
3 | # oauth client settings
4 | oauth.client.id = demo
5 | oauth.client.secret = 50dN92
6 |
7 | # oauth spring filter settings
8 | oauth.server.url = http://localhost:8090
9 | oauth.spring.filter.token.store.type = cookie
10 | oauth.spring.filter.token.name = oauth-token
11 | oauth.spring.filter.skip.url = /login.html,/logout.html,/index.html,/api/login,/api/logout
--------------------------------------------------------------------------------
/sample/demo-spring-boot-web/src/main/resources/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 演示OAuth 2.0 Resource Owner Password Grant
6 |
7 |
8 | 演示OAuth 2.0 Resource Owner Password Grant
9 | 请先到登录页面,尝试登录,然后访问后端api,获取用户登录信息
10 |
11 |
12 |
13 |
14 |
15 | 请点击访问后端API,获取用户信息
16 |
17 | 获取用户信息
18 |
19 |
20 |
21 |
22 |
23 |
24 | 回到首页
25 | 登录页面
26 | 注销登录页面
27 |
28 |
29 |
30 |
31 |
52 |
--------------------------------------------------------------------------------
/sample/demo-spring-boot-web/src/main/resources/static/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 演示OAuth 2.0 Resource Owner Password Grant
6 |
7 |
8 | 演示-登录
9 | 请输入用户名和密码,并点击登录按钮
10 |
11 |
28 |
29 |
30 | 回到首页
31 | 登录页面
32 | 注销登录页面
33 |
34 |
35 |
36 |
37 |
38 |
74 |
75 |
--------------------------------------------------------------------------------
/sample/demo-spring-boot-web/src/main/resources/static/logout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 演示OAuth 2.0 Resource Owner Password Grant
6 |
7 |
8 | 演示 - Logout
9 | 请点击登出按钮,这会清除登录的cookie信息。
10 |
11 |
12 |
13 |
14 | 请点击登出按钮
15 |
16 | 登出
17 |
18 |
19 |
20 |
21 |
22 |
23 | 回到首页
24 | 登录页面
25 | 注销登录页面
26 |
27 |
28 |
29 |
30 |
57 |
--------------------------------------------------------------------------------
/sample/demo-web-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | oauth-sample
7 | com.pphh.demo
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | demo-web-service
13 | pom
14 |
15 | resource-client
16 | resource-server
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/sample/demo-web-service/resource-client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | demo-web-service
7 | com.pphh.demo
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | resource-client
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 | com.pphh.demo
21 | oauth-spring-boot-autoconfigure
22 |
23 |
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-maven-plugin
30 | ${springboot.version}
31 |
32 |
33 |
34 | repackage
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/sample/demo-web-service/resource-client/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port = 9004
2 |
3 | # oauth spring filter settings - remote api
4 | oauth.server.url = http://localhost:8090
5 |
6 | # oauth client settings
7 | oauth.client.id = demo
8 | oauth.client.secret = 50dN92
9 |
10 | # resource server
11 | resource.server.url = http://localhost:9003/hello
--------------------------------------------------------------------------------
/sample/demo-web-service/resource-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | demo-web-service
7 | com.pphh.demo
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | resource-server
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 | com.pphh.demo
21 | oauth-spring-boot-autoconfigure
22 |
23 |
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-maven-plugin
30 | ${springboot.version}
31 |
32 |
33 |
34 | repackage
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/sample/demo-web-service/resource-server/src/main/java/com/pphh/oauth/sample/ResourceServer.java:
--------------------------------------------------------------------------------
1 | package com.pphh.oauth.sample;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.http.HttpStatus;
6 | import org.springframework.http.ResponseEntity;
7 | import org.springframework.web.bind.annotation.GetMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | /**
11 | * Please add description here.
12 | *
13 | * @author huangyinhuang
14 | * @date 8/2/2018
15 | */
16 | @SpringBootApplication
17 | @RestController
18 | public class ResourceServer {
19 |
20 | public static void main(String[] args) {
21 | SpringApplication.run(ResourceServer.class, args);
22 | }
23 |
24 | @GetMapping("/hello")
25 | public ResponseEntity greet() {
26 | return new ResponseEntity<>("hello, I am protected by oauth filter.", HttpStatus.OK);
27 | }
28 |
29 | @GetMapping("/login")
30 | public ResponseEntity login() {
31 | return new ResponseEntity<>("hello, this is login api.", HttpStatus.OK);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/sample/demo-web-service/resource-server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port = 9003
2 |
3 | # oauth spring filter settings - remote api
4 | oauth.server.url = http://localhost:8090
5 |
6 | # oauth spring filter settings
7 | oauth.spring.filter.type = all-check-by-skip
8 | oauth.spring.filter.token.store.type = header
9 | oauth.spring.filter.token.name = resource-token
10 | oauth.spring.filter.special.urls = /login
11 |
--------------------------------------------------------------------------------