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 vs Username 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/

原文地址:https://www.cnblogs.com/chucklu/p/10346388.html

时间: 2024-10-14 02:52:42

ASP.NET OAuth Authorization - Difference between using ClientId and Secret and Username and Password的相关文章

ASP.NET Core Authorization

ASP.NET Core Authorization 本文目录 Asp.net Core 对于授权的改动很友好,非常的灵活,本文以MVC为主,当然如果说webapi或者其他的分布式解决方案授权,也容易就可以实现单点登录都非常的简单,可以使用现成的IdentityServer框架或者自定义实现动非常方便和干净,如果你在运行示例代码的时候未达到预期效果,请把文章拉到结尾寻找答案. 本文示例代码下载,github我这访问不了,暂且直接上传博客园存储了. 准备 使用Authorization 使用全局授

ASP.NET没有魔法——ASP.NET OAuth、jwt、OpenID Connect

上一篇文章介绍了OAuth2.0以及如何使用.Net来实现基于OAuth的身份验证,本文是对上一篇文章的补充,主要是介绍OAuth与Jwt以及OpenID Connect之间的关系与区别. 本文主要内容有: ● Jwt简介 ● .Net的Jwt实现 ● OAuth与Jwt ● .Net中使用Jwt Bearer Token实现OAuth身份验证 ● OAuth与OpenID Connect 注:本章内容源码下载:https://files.cnblogs.com/files/selimsong/

ASP.NET OAuth:access token的加密解密,client secret与refresh token的生成

在ASP.NET OWIN OAuth(Microsoft.Owin.Security.OAuth)中,access token 的默认加密方法是: 1) System.Security.Cryptography.DpapiDataProtector.Protect() 2) Convert.ToBase64String() 3) .TrimEnd('=').Replace('+', '-').Replace('/', '_'); access token 的默认解密方法是: 1) System

教你实践ASP.NET Core Authorization

参考页面: http://www.yuanjiaocheng.net/ASPNET-CORE/core-razor-layout.html http://www.yuanjiaocheng.net/ASPNET-CORE/core-view-start.html http://www.yuanjiaocheng.net/ASPNET-CORE/core-import-view.html http://www.yuanjiaocheng.net/ASPNET-CORE/core-razor-tag

ASP.NET OAuth:解决refresh token无法刷新access token的问题

最近同事用iOS App调用Open API时遇到一个问题:在access token过期后,用refresh token刷新access token时,服务器响应"invalid_grant"错误:而在access token没有过期的情况下,能正常刷新access token. 先查看了一下OAuth规范中的“Refreshing an Expired Access Token”流程图,以确认客户端的操作流程有没有问题. 问题发生在上图中的(G)操作步骤.iOS App就是按上图的

[转]教你实践ASP.NET Core Authorization

本文转自:http://www.cnblogs.com/rohelm/p/Authorization.html 本文目录 Asp.net Core 对于授权的改动很友好,非常的灵活,本文以MVC为主,当然如果说webapi或者其他的分布式解决方案授权,也容易就可以实现单点登录都非常的简单,可以使用现成的IdentityServer框架或者自定义实现动非常方便和干净,如果你在运行示例代码的时候未达到预期效果,请把文章拉到结尾寻找答案. 本文示例代码下载,github我这访问不了,暂且直接上传博客园

ASP.NET控件的ID,ClientID,UniqueId的区别

一般情况下三者相同(没有父控件) ID:获取或设置分配给服务器控件的编程标识符.分配给控件的编程标识符. (可写) 设置服务器控件上的此属性可提供对服务器控件的属性.事件和方法的编程访问.Web 开发人员可以通过在 ASP.NET 服务器控件的开始标记中声明 ID 属性来设置此属性.如果没有为服务器控件指定该属性(以声明方式或编程方式),则可通过其父控件的 Controls 属性获取对该控件的引用.(见下)注意 在此属性中包含空格将导致 ASP.NET 页分析器错误. :获取服务器控件的唯一的.

The OAuth 2.0 Authorization Framework-摘自https://tools.ietf.org/html/rfc6749

Internet Engineering Task Force (IETF) D. Hardt, Ed. Request for Comments: 6749 Microsoft Obsoletes: 5849 October 2012 Category: Standards Track ISSN: 2070-1721 The OAuth 2.0 Authorization Framework Abstract The OAuth 2.0 authorization framework enab

在ASP.NET中实现OAuth2.0(二)之打造自己的API安全策略

1.场景介绍 公司开发了一款APP产品,前期提供的api接口都是裸奔状态 举个例子:想要获取某一个用户的数据,只需要传递该用户的ID就可以拿走数据(说多了都是泪) 现在想给这些接口穿个衣服,加个壳(对客户端进行授权) 2.业务实现 > 搭建授权服务器和资源服务器 > 给App客户端发放AppId和AppSecret > 用户向App客户端提供自己的账号和密码 > App客户端将AppId.AppSecret.账号和密码提交到授权服务器 > 授权服务器通过授权,发放token和