# security-oauth **Repository Path**: fastLang/security-oauth ## Basic Information - **Project Name**: security-oauth - **Description**: 这是一个非常简单地集成 spring security 和 OAuth2.0 的 密码模式的简单实例,其中文件都有注释,很容易看懂, 技术支持: springboot 2.3.10.RELESE mybatis-plus 3.4.1 spring security oauth2.0 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-08-23 - **Last Updated**: 2021-08-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README **这是一个非常简单地集成 spring security 和 OAuth2.0 的 密码模式的简单实例,其中文件都有注释,很容易看懂,** **_技术支持: springboot 2.3.10.RELESE mybatis-plus 3.4.1 spring security oauth2.0_** **1> 密码登录模式 ** ### (1)请求路径 : (http://192.168.1.93:10080/oauth/token?username=admin&password=admin&grant_type=password&client_id=client&client_secret=123456&grant_type=refresh_token) `{ "access_token": "7fd8b307-3a66-4d03-8f25-d6441bda82f6", "token_type": "bearer", "refresh_token": "5ff857b4-1729-458a-a43c-c6d1328b4955", "expires_in": 6987, "scope": "read write" }` ![登录获取token](https://images.gitee.com/uploads/images/2021/0507/165707_d8e28b80_1960502.png "微信图片_20210507165541.png") (2) 刷新 token (//http://localhost:10080/oauth/token?grant_type=refresh_token&client_id=client&client_secret=123456&refresh_token=5ff857b4-1729-458a-a43c-c6d1328b4955) `{ "access_token": "39224da0-d19d-4227-a35b-92a6b775153d", "token_type": "bearer", "refresh_token": "5ff857b4-1729-458a-a43c-c6d1328b4955", "expires_in": 7199, "scope": "read write" }` ![刷新token](https://images.gitee.com/uploads/images/2021/0507/165741_98ca20bd_1960502.png "微信图片_20210507165609.png") ### 2>补充:客户端模式: 授权服务器增加配置如下: ` .and().withClient("client_1") .secret(passwordEncoder().encode("123456")) .authorizedGrantTypes("client_credentials") .scopes("read", "write") .authorities("client_credentials") .accessTokenValiditySeconds(7200) ` 资源服务器做相应的修改,授权成功后即可访问: ` @Override public void configure(HttpSecurity http) throws Exception { http.csrf().disable()//禁用了 csrf 功能 .authorizeRequests()//限定签名成功的请求 .antMatchers("/test/**","/admin/**").authenticated()//签名成功后可访问 //.antMatchers("/admin/login","/oauth/**").permitAll() .anyRequest().permitAll()//其他没有限定的请求,允许访问 .and().anonymous()//对于没有配置权限的其他请求允许匿名访问 .and().formLogin()//使用 spring security 默认登录页面 .and().httpBasic();//启用http 基础验证 } ` 请求其他资源: http://localhost:10080/sys/user/getAllUser?access_token=39224da0-d19d-4227-a35b-92a6b775153d 下面是携带token请求到的其他资源 `[ { "id": 2, "name": "admin", "password": "$2a$10$Yks2LoqzBUHEWjyLCnsdtepI4oCNip9yNdf67y19ewF8geORNAO5m" }, { "id": 3, "name": "xuweichao", "password": "$2a$10$kmFQOKZw8l776qXp00Lq9e2drL5MUSpG9YHnQtQwbVzyUjJQwHNha" } ]` 数据库在 doc文件下 导入数据库就好了 命令输入: git push origin master 出现 failed to push some refs to 'https://github.com/CrazyDony/text.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 原因:自己分支版本低于主版本 执行以下代码就可以了 git push -u origin master-f