3 Star 7 Fork 4

QiHaiYan / ng-boot-oauth

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

ng-boot-oauth

oauth2 demo 程序,使用了angularjs 1.x 和 springboot框架。

默认的用户名是 admin, 密码是 111111

1. 特点

模块

项目包括3个模块:

  • authserver
  • ui (oauth2 code flow的客户端应用)
  • ui-implicit (oauth2 implicit flow的客户端应用,有一个独立的前端模块)

前端

  • ES6
  • AngularJs 1.x
  • webpack dev server hot-reload (通过在index.html中引用web-dev-server的js文件,在DEV模式下实现自动加载功能)
<% if (webpackConfig.metadata.ENV === 'dev') { %>
<!-- webpack dev server reload -->
<script src="http://<%= webpackConfig.metadata.host %>:<%= webpackConfig.metadata.port %>/webpack-dev-server.js"></script>
<!-- end webpack dev server reload -->
<% } %>

后端

  • Gradle 构建工具
  • Spring Boot
  • Spring security Oauth2
  • Thymeleaf 模版引擎

2. 在开发模式下运行

注意 ui 模块和 ui-implicit 模块由于都用了8080端口,所以不能同时运行,每次只能运行一个模块。

获取代码

git clone https://github.com/qihaiyan/ng-boot-oauth.git
cd ng-boot-oauth

运行 OAuth2 Server

cd authserver
./gradlew bootRun

运行 ui 模块

cd ui
./gradlew bootRun

通过 http://localhost:8080 这个地址访问应用。

运行 ui-implicit 模块

  • 运行后端服务
cd ui-implicit
./gradlew bootRun
  • 运行前端模块

如果是第一次运行程序,需要先安装依赖。

cd ui-implicit
npm install

依赖安装完成后,运行前端程序

cd ui-implicit
npm run dev
  • CORS 问题

在DEV模式下运行 ui-implicit 前端模块时,如果采用webpack-dev-server的默认配置会出现CORS错误。

需要在webpack.config.js中调整dev-server的配置,调用后端API的代理也可以在这儿进行配置:

devServer: {
            port: 3000,
            contentBase: './src/main/frontend',
            headers: {
                'Access-Control-Allow-Origin': 'http://localhost:8080',
                'Access-Control-Allow-Credentials': 'true',
                'Access-Control-Allow-Headers': 'authorization',
                'Access-Control-Allow-Methods': 'GET'
            },
            // proxy: {
            //     '/user': 'http://localhost:8080/'
            // },
        },

通过 http://localhost:8080 这个地址访问应用。

3. 在生产模式下运行

编译和打包项目:

gradle build

运行 authserver:

cd authserver/
java -jar ./build/libs/ng-boot-oauth-0.0.1.jar

运行 ui 模块:

cd ui/
java -jar ./build/libs/ng-boot-oauth-ui-0.0.1.jar

或者是运行 ui-implicit 模块:

cd ui-implicit/
java -jar ./build/libs/ng-boot-oauth-ui-implicit-0.0.1.jar

通过 http://localhost:8080 这个地址访问应用。

MIT License Copyright (c) 2016 HaiYan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

oauth2 demo with angularjs and springboot 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/qihy/ng-boot-oauth.git
git@gitee.com:qihy/ng-boot-oauth.git
qihy
ng-boot-oauth
ng-boot-oauth
master

搜索帮助