ASP.NET OAuth Authorization - Difference between using ClientId and Secret and Username and Password
What I don't fully understand is the use of
ClientId and Secret
vsUsername and Password
. The code I pasted generates a token by username and password and I can work with that token (until it expires), but when I try to get a refresh token, I must have the ClientId.Also, if a token expires, the correct way is to send the refresh token and get a new token? What if the refresh token gets stolen? isn't it the same as a username & password getting stolen?
In OAuth2 is essential to authenticate both the user and the client in any authorization flow defined by the protocol. The client authentication (as you may guess) enforces the use of your API only by known clients. The serialized access token, once generated, is not bound to a specific client directly. Please note that the ClientSecret
must be treated as a confidential information, and can be used only by clients that can store this information in some secure way (e.g. external services clients, but not javascript clients).
The refresh token is simply an alternative "grant type" for OAuth2, and, as you stated correctly, will substitute the username and password pair for a User. This token must be treated as confidential data (even more confidential than the access token), but gives advantages over storing the username & password on the client:
- it can be revoked by the user if compromised;
- it has a limited lifetime (usually days or weeks);
- it does not expose user credentials (an attacker can only get access tokens for the "scope" the refresh token was issued).
I suggest you to read more about the different grant types defined in OAuth 2 checking in the official draft. I also recommend you this resource I found very useful when firstly implemented OAuth2 in Web API myself.
Sample requests
Here are two request examples using fiddler, for Resource Owner Password Credentials Grant
:
and for Refresh Token Grant
:
https://www.oauth.com/oauth2-servers/client-registration/client-id-secret/
ASP.NET OAuth Authorization - Difference between using ClientId and Secret and Username and Password的更多相关文章
- ASP.NET OAuth、jwt、OpenID Connect
ASP.NET OAuth.jwt.OpenID Connect 上一篇文章介绍了OAuth2.0以及如何使用.Net来实现基于OAuth的身份验证,本文是对上一篇文章的补充,主要是介绍OAuth与J ...
- ASP.NET Core Authorization
ASP.NET Core Authorization 本文目录 Asp.net Core 对于授权的改动很友好,非常的灵活,本文以MVC为主,当然如果说webapi或者其他的分布式解决方案授权,也容易 ...
- ASP.NET没有魔法——ASP.NET OAuth、jwt、OpenID Connect
上一篇文章介绍了OAuth2.0以及如何使用.Net来实现基于OAuth的身份验证,本文是对上一篇文章的补充,主要是介绍OAuth与Jwt以及OpenID Connect之间的关系与区别. 本文主要内 ...
- ASP.NET OAuth 2.0 新手上路
OAuth2.0资料 初衷:一直想整理授权系列demo,让自己项目高端大尚,列出新手授权系列,帮助小白程序员不用在为授权头疼 OAuth 允许用户提供一个令牌,而不是用户名和密码来访问他们存放在特定服 ...
- ASP.NET OAuth:解决refresh token无法刷新access token的问题
最近同事用iOS App调用Open API时遇到一个问题:在access token过期后,用refresh token刷新access token时,服务器响应"invalid_gran ...
- ASP.NET OAuth:access token的加密解密,client secret与refresh token的生成
在 ASP.NET OWIN OAuth(Microsoft.Owin.Security.OAuth)中,access token 的默认加密方法是: 1) System.Security.Crypt ...
- [转]教你实践ASP.NET Core Authorization
本文转自:http://www.cnblogs.com/rohelm/p/Authorization.html 本文目录 Asp.net Core 对于授权的改动很友好,非常的灵活,本文以MVC为主, ...
- 教你实践ASP.NET Core Authorization
本文目录 Asp.net Core 对于授权的改动很友好,非常的灵活,本文以MVC为主,当然如果说webapi或者其他的分布式解决方案授权,也容易就可以实现单点登录都非常的简单,可以使用现成的Iden ...
- ASP.NET控件的ID,ClientID,UniqueId的区别
一般情况下三者相同(没有父控件) ID:获取或设置分配给服务器控件的编程标识符.分配给控件的编程标识符. (可写) 设置服务器控件上的此属性可提供对服务器控件的属性.事件和方法的编程访问.Web 开发 ...
随机推荐
- 2017-2018-2 20165330 实验三《敏捷开发与XP实现》实验报告
实验内容 P基础 XP核心实践 相关工具 实验步骤 (一)敏捷开发与XP 软件开发:即将软件需求分析.软件设计.软件构建.软件测试和软件维护这些相关技术和过程统一到一个体系中 敏捷开发:是一种以人为核 ...
- 通过/dev/mem只能访问高端内存以下的内核线性地址空间
http://blog.chinaunix.net/uid-20564848-id-74706.html </proc/iomem和/proc /ioports对应的fops> < ...
- IBM DEVOPS IN CLOUD--chaos monkey
- getResource()和getResourceAsStream以及路径问题(转)
用JAVA获取文件,听似简单,但对于很多像我这样的新人来说,还是掌握颇浅,用起来感觉颇深,大常最经常用的,就是用JAVA的File类,如要取得c:/test.txt文件,就会这样用File file ...
- tornado调用ioloop TracebackFuture实现非堵塞的模块
转载http://xiaorui.cc/2014/11/26/tornado调用ioloop-tracebackfuture实现非堵塞的模块/ 当然实现的方法,还是存在点问题的, 但是最少流程是跑通了 ...
- Jmeter(六)文件上传和下载文件
一.Jmeter上传文件 编写脚本: 首先添加一个线程组,然后在线程组里面添加一个http请求,因为是发送数据,所有是post请求,写好上传的地址,然后写好文件路径 ...
- TensorFlow学习笔记(三)-- feed_dict 使用
个人理解:就是TF的一种输入语法. 跟C语言的scanf(),C++的 cin>> 意思差不多,只是长相奇怪了点而已. 做完下面几个例子,基本也就适应了. 首先占位符申请空间:使用的时候, ...
- java堆结构和垃圾回收
JVM内存结构和垃圾回收一.JVM垃圾收集算法1.引用计数算法 每个对象有一个引用计数属性,新增一个引用时计数加1,引用释放时计数减1,计数为0时可以回收. 此方法简单,无法解决对象互相循环引用的问题 ...
- 新建虚拟机与本机ping不通(一招解决)
初始新建虚拟机或者复制虚拟机后,发现虚拟机能ping通内外网,但是本机无法ping通虚拟机,xshell也无法连接虚拟机 这时候就很头疼了,因为要上传很多文件到虚拟机上面 解决办法: 1.关闭虚拟机后 ...
- 重新编写equals()方法,hashCode()方法,以及toString(),提供自定义的相等标准,以及自描述方法
下面给出一个实例,重新编写equals()方法,提供自定义的相等标准 public class PersonTest { public static void main(String[] args) ...