简化模式定义

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

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. Spring自学教程-声明式事务处理(六)

    Spring事务处理分两种: 一.编程式事务:在程序中控制事务开始,执行和提交: 1.1 使用TransactionTemplate, 使用回调函数执行事务,不需要显示开始事务,不需要显示提交事务,但 ...

  2. 布隆过滤器(BoomFilter)

    1.原理:           a.解决的问题:                判断一个元素是否在一个集合中             b.Hash表的特点:                i.快速准确 ...

  3. 利用反射动态从程序集dll执行方法和属性

    程序结构: //获取程序集 Assembly asb = Assembly.LoadFrom(path);//path为程序集的物理路径 //获取程序集下面的Student类 Type documen ...

  4. FreeRTOS基础以及UIP之协程--C语言剑走偏锋

    在FreeRTOS中和UIP中,都使用到了一种C语言实现的多任务计数,专业的定义叫做协程(coroutine),顾名思义,这是一种协作的例程, 跟具有操作系统概念的线程不一样,协程是在用户空间利用程序 ...

  5. VS2010环境下用ANSI C创建DLL和使用方法(转)

    源:VS2010环境下用ANSI C创建DLL和使用方法 . 创建DLL工程 1.2 创建一个dll工程. 操作:a.文件->新建->项目->Win32控制台应用程序. b.输入工程 ...

  6. Warning: Attempt to present on whose view is not in模态跳转问题

    错误分析:            controller A present controller B ,前提是A的view要存在,如果不存在,就会报这个错.   解决方法:             将 ...

  7. iOS动画特效

    关于图层的几个坐标系. 对于ios来说,坐标系的(0,0)点在左上角,就是越往下,Y值越大.越往右,X值越大. 一个图层的frame,它是position,bounds,anchorPoint和tra ...

  8. Phplot--一些记录

    1.一张图片画俩次 需要设置 $phplot->SetPrintImage(0); 参考  http://www.phplot.com/phplotdocs/ex-twoplot1.html

  9. 通过div模拟table

    参考: https://css-tricks.com/complete-guide-table-element/ 不要使用内联样式,但只是为了了解这里是如何去: <section style=& ...

  10. Linux安装Tomcat外部不能访问

    Linux安装Tomcat后本地可以正常访问,可是这时Tomcat还不能被外界访问需要在Linux默认防护墙上打开8080端口 打开 /etc/sysconfig/iptables [root@loc ...