AccessToken-->Password Grant
https://www.oauth.com/oauth2-servers/access-tokens/password-grant/
The Password grant is used when the application exchanges the user’s username and password for an access token. This is exactly the thing OAuth was created to prevent in the first place, so you should never allow third-party apps to use this grant.
A common use for this grant type is to enable password logins for your service’s own apps. Users won’t be surprised to log in to the service’s website or native application using their username and password, but third-party apps should never be allowed to ask the user for their password.
Request Parameters
The access token request will contain the following parameters.
grant_type
(required) – Thegrant_type
parameter must be set to “password”.username
(required) – The user’s username.password
(required) – The user’s password.scope
(optional) – The scope requested by the application.- Client Authentication (required if the client was issued a secret)
If the client was issued a secret, then the client must authenticate this request. Typically the service will allow either additional request parameters client_id
and client_secret
, or accept the client ID and secret in the HTTP Basic auth header.
Example
The following is an example password grant the service would receive.
POST /oauth/token HTTP/1.1
Host: authorization-server.com
grant_type=password
&username=user@example.com
&password=1234luggage
&client_id=xxxxxxxxxx
&client_secret=xxxxxxxxxx
See Access Token Response for details on the parameters to return when generating an access token or responding to errors.
GET /Chuck_WebApi/oauth/token HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
cache-control: no-cache
Postman-Token: 77e99b5f-d31e-4379-a64c-ddc511d42781
grant_type=passwordusername=adminpassword=passwordundefined=undefined
To allow only the grant types you want it's enough to inherit from OAuthAuthorizationServerProvider
. Then you need to override two methods:
- ValidateClientAuthentication - to validate that the origin of the request is a registered
client_id
- GrantResourceOwnerCredentials - to validate provided
username
andpassword
when thegrant_type
is set topassword
For more information here is the documentation of GrantResourceOwnerCredentials method:
Called when a request to the Token endpoint arrives with a "grant_type" of "password". This occurs when the user has provided name and password credentials directly into the client application's user interface, and the client application is using those to acquire an "access_token" and optional "refresh_token". If the web application supports the resource owner credentials grant type it must validate the context.Username and context.Password as appropriate. To issue an access token the context.Validated must be called with a new ticket containing the claims about the resource owner which should be associated with the access token. The application should take appropriate measures to ensure that the endpoint isn’t abused by malicious callers. The default behavior is to reject this grant type.
需要注意的是:
client_credentials
Called when a request to the Token endpoint arrives with a "grant_type" of "password".
This occurs when the user has provided name and password credentials directly into the client application's user interface, and the client application is using those to acquire an "access_token" and optional "refresh_token".
If the web application supports the resource owner credentials grant type it must validate the context.Username and context.Password as appropriate.
To issue an access token the context.Validated must be called with a new ticket containing the claims about the resource owner which should be associated with the access token.
The default behavior is to reject this grant type. See also http://tools.ietf.org/html/rfc6749\#section-4.3.
经过测试,发现下面这个才是有效的
GET /Chuck_WebApi/oauth/token HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
cache-control: no-cache
Postman-Token: ce49a101-df6e-4b7c-9217-e112b387b784
grant_type=client_credentialsusername=adminpassword=password
换了另外一种
GET http://localhost/Chuck_WebApi/oauth/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
cache-control: no-cache
Postman-Token: 3b870eb3-1c29-4b5e-9dcd-297e3f582c27
User-Agent: PostmanRuntime/7.6.0
Accept: */*
Host: localhost
accept-encoding: gzip, deflate
content-length: 75
Connection: keep-alivegrant_type=password&username=admin&password=password&client_id=testClientId
AccessToken-->Password Grant的更多相关文章
- Dynamics 365本地部署版本配置OAuth 2 Password Grant以调用Web API
微软动态CRM专家罗勇 ,回复330或者20190504可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me! 根据官方建议,不要再使用Dynamics 365 Custome ...
- 基于OWIN WebAPI 使用OAuth授权服务【客户端验证授权(Resource Owner Password Credentials Grant)】
适用范围 前面介绍了Client Credentials Grant ,只适合客户端的模式来使用,不涉及用户相关.而Resource Owner Password Credentials Grant模 ...
- IdentityServer4之Resource Owner Password Credentials(资源拥有者密码凭据许可)
IdentityServer4之Resource Owner Password Credentials(资源拥有者密码凭据许可) 参考 官方文档:2_resource_owner_passwords ...
- My sql添加远程用户root密码为password
添加远程用户root密码为password grant all privileges on *.* to root@localhost identified by '123321' with gran ...
- springboot+spring security +oauth2.0 demo搭建(password模式)(认证授权端与资源服务端分离的形式)
项目security_simple(认证授权项目) 1.新建springboot项目 这儿选择springboot版本我选择的是2.0.6 点击finish后完成项目的创建 2.引入maven依赖 ...
- IdentityServer Resource Owner Password
Resource Owner Password 模式需要自己实现用户名密码的校验 新增ResourceOwnerPasswordValidator实现IResourceOwnerPasswordVal ...
- 转 - spring security oauth2 password授权模式
原贴地址: https://segmentfault.com/a/1190000012260914#articleHeader6 序 前面的一篇文章讲了spring security oauth2的c ...
- SpringBoot2.x版本整合SpringSecurity、Oauth2进行password认证
很多人在进行项目开发时都会用到Oauth2.0结合SpringSecurity或者Shiro进行权限拦截以及用户验证,网上也有很多的案例,前几天项目里边需要用到,顺便整合了进来,特此写篇博客,记录下过 ...
- mysql安装后改动port号password默认字符编码
1.改动password grant all privileges on *.* to 'root'@'localhost' identified by 'new password'; 2.改动por ...
随机推荐
- 《Django By Example》第十二章(终章) 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第十二章,全书最后一章,终于到这章 ...
- Codeforces Round #118 (Div. 1) A. Plant
A. Plant 题目链接:http://codeforces.com/problemset/problem/185/A 题意:一个植物会长,一开始是一个正三角形,每过一年,一个向上的正三角形会变成三 ...
- 剑指Offer——对称的二叉树
题目描述: 请实现一个函数,用来判断一颗二叉树是不是对称的.注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的. 分析: 递归解法. 如果对称点一个有一边为空一边不为空,或者是对称点数值不一 ...
- 剑指Offer——第一个只出现一次的字符位置
题目描述: 在一个字符串(1<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置. 分析: 用一个数组统计每个字符出现的次数. 再次扫描数组,如果找到 ...
- squee_spoon and his Cube VI---郑大校赛(求最长子串)
市面上最常见的魔方,是三阶魔方,英文名为Rubik's Cube,以魔方的发明者鲁比克教授的名字命名.另外,二阶魔方叫Pocket Cube,它只有2*2*2个角块,通常也就比较小:四阶魔方叫Reve ...
- VMwareWorkstations中安装ubuntu,apt install报E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
ubuntu中apt安装软件python时报: E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily un ...
- 临时修改当前crontab编辑器
EDITOR=viexport EDITOR然后crontab -e就不会有这个问题了
- maven 之nexus仓库管理_私服配置
1.下载nexus私服 下载地址:http://www.sonatype.org/downloads/nexus-latest.war 2.解压 解压以下压缩包 3.配置环境变量 *\nexus-2. ...
- mysql监控优化(一)连接数和缓存
一.mysql的连接数 MYSQL数据库安装完成后,默认最大连接数是100,一般流量稍微大一点的论坛或网站这个连接数是远远不够的,连接数少的话,在大并发下连接数会不够用,会有很多线程在等待其他连接释放 ...
- Shiro起步
1.测试环境 IntelliJ Idea 2.pom配置 <?xml version="1.0" encoding="UTF-8"?> <p ...