简化模式定义

通过客户端的后台服务器,与“服务提供商”的认证服务器进行认证。(和授权码模式差不多哦)

1、用户访问客户端,后者将前者导向认证服务器。
2、用户选择是否给予客户端授权。
3、假设用户给予授权,认证服务器会直接向客户端发送访问令牌(access token)。
4、Client拿着access token去访问Resource资源

注意:红色字体部分是与授权码模式最根本的区别哦

简化模式的工作流程图:

图 1 (网上搜到的简化模式工作流程图说明)

新建项目:ImplicitGrant

AuthorizationServer与ResourceServer还是用之前的项目

新建Index.cshtml

    <form id="form1">
<div>
Access Token<br />
<input id="AccessToken" name="AccessToken" />
<input id="Authorize" type="button" name="signin.AccessToken" value="向认证服务器申请授权" />
<br />
<input id="CallApi" name="submit.CallApi" value="访问受控资源" type="button" />
</div>
<div id="output">
</div>
</form> 
     var authorizeUri = 'http://localhost:8270/OAuth/Authorize';
var returnUri = 'http://localhost:3622/Home/SignIn';
var apiUri = 'http://localhost:8001/api/Values'; $('#Authorize').click(function () {
var nonce = 'my-nonce'; var uri = addQueryString(authorizeUri, {
'client_id': '7890ab',
'redirect_uri': returnUri,
'state': nonce,
'scope': 'scope1 scope2',
'response_type': 'token',
}); window.oauth = {};
window.oauth.signin = function (data) {
if (data.state !== nonce) {
return;
} $('#AccessToken').val(data.access_token);
} window.open(uri, 'Authorize', 'width=640,height=480');
}); $('#CallApi').click(function () {
$.ajax(apiUri, {
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + $('#AccessToken').val());
},
dataType: 'text',
cache: false,
success: function (data) {
console.log(data);
$('#output').text(data);
}
});
});

OK,自此,简化模式测试项目有效代码已经完成了

注意:逻辑是故意写在html页面而没有写在后台cs页面的哦,这是简化模式形成的原因

运行项目试试

开始授权

点击认证按钮,出现认证页面和授权码页面一样

点击授权,直接返回的就是token

点击访问受控资源,发现没有预期那样返回资源数据

这是js跨域的问题,需要在ResourceServer项目加上“microsoft.aspnet.webapi.cors”引用

并在WebApiConfig.cs页面加上

// 跨域配置
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));

在ValuesController中的Get方式上贴上[HttpGet]  

   public class ValuesController : ApiController
{
[HttpGet]
[Authorize]
public string Get()
{
return "lanxiaoke";
}
}

再次试试,成功返回数据

 asp.net权限认证系列 

  1. asp.net权限认证:Forms认证
  2. asp.net权限认证:HTTP基本认证(http basic)
  3. asp.net权限认证:Windows认证
  4. asp.net权限认证:摘要认证(digest authentication)
  5. asp.net权限认证:OWIN实现OAuth 2.0 之客户端模式(Client Credential)
  6. asp.net权限认证:OWIN实现OAuth 2.0 之密码模式(Resource Owner Password Credential)
  7. asp.net权限认证:OWIN实现OAuth 2.0 之授权码模式(Authorization Code)
  8. asp.net权限认证:OWIN实现OAuth 2.0 之简化模式(Implicit)

asp.net权限认证:OWIN实现OAuth 2.0 之简化模式(Implicit)的更多相关文章

  1. asp.net权限认证:OWIN实现OAuth 2.0 之客户端模式(Client Credential)

    asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证 ...

  2. asp.net权限认证:OWIN实现OAuth 2.0 之密码模式(Resource Owner Password Credential)

    asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证 ...

  3. asp.net权限认证:OWIN实现OAuth 2.0 之授权码模式(Authorization Code)

    asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证 ...

  4. asp.net权限认证:Windows认证

    asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证 ...

  5. asp.net权限认证:Forms认证

    asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证 ...

  6. asp.net权限认证:HTTP基本认证(http basic)

    asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证 ...

  7. asp.net权限认证:摘要认证(digest authentication)

    asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证 ...

  8. [转]asp.net权限认证:摘要认证(digest authentication)

    本文转自:http://www.cnblogs.com/lanxiaoke/p/6357501.html 摘要认证简单介绍 摘要认证是对基本认证的改进,即是用摘要代替账户密码,从而防止明文传输中账户密 ...

  9. [转]asp.net权限认证:HTTP基本认证(http basic)

    本文转自:http://www.cnblogs.com/lanxiaoke/p/6353955.html HTTP基本认证示意图 HTTP基本认证,即http basic认证. 客户端向服务端发送一个 ...

随机推荐

  1. 求最长连续公共子序列 POJ 3080

    Description The Genographic Project is a research partnership between IBM and The National Geographi ...

  2. find命令--xargs--exec

    find命令 1.1.find命令选项-name 按照文件名查找-perm 按照文件权限来查找-prune 可以使用find命令排除当前文件夹,不查找-user 可以按照文件属主来查找-group 可 ...

  3. DNS架设准备+申请领域查询授权

    1. 架设DNS服务器首先我们得安装一下的软件[root@bogon ~]# rpm -qa | grep ^bindbind-libs-9.8.2-0.37.rc1.el6.i686 <==给 ...

  4. PHP 判断几秒前,几分钟,几小时前

    PHP 对于时间的过了多久的判断,几秒前,几分钟前,几小时前,$time = strtotime("2017-01-15 14:42:00"); $time = strtotime ...

  5. Extjs4中的store

      Extjs 4引入新的数据包,其中新增了不少新类并对旧有的类作出了修整.使数据包更强大和更容易使用.  本章我们将学习一下内容: 2.1. 概述新特性      Extjs4的数据包引入了如Mod ...

  6. S3C2440时钟系统详解

    在讲述系统时钟之前,因为这些设备都是挂靠在系统时钟上的,所以必须先说系统时钟,S3C2440的时钟系统如下 外部时钟源分两种,晶振或者外部频率,由om3-2选择,时钟电路根据两种选择也有两种 我们来分 ...

  7. 【转】成为Linux内核高手的四个方法

    我曾经问别人如何开始内核编程的学习,他们基本上都说:①如果你不需要了解内核是如何为你工作的,你为何要尝试呢?②你应该订阅Linux内核邮件列表,然后努力去理解.③如果你不去编写针对Linux内核的代码 ...

  8. 4.ICMP协议,ping和Traceroute

    1.IMCP协议介绍 前面讲到了,IP协议并不是一个可靠的协议,它不保证数据被送达,那么,自然的,保证数据送达的工作应该由其他的模块来完成.其中一个重要的模块就是ICMP(网络控制报文)协议. 当传送 ...

  9. box-sizing

    Over the generations, people realized that math is not fun, so a new CSS property called box-sizing ...

  10. Bootstrap3写的红色警告框样式组件

    用的是BT3的类和fa的图标 <!DOCTYPE html><html><head lang="en">    <meta charset ...