首页 > 其他分享 >Creating your own OpenID Connect server with ASOS: testing your authorization server with Postman

Creating your own OpenID Connect server with ASOS: testing your authorization server with Postman

时间:2023-05-19 18:55:45浏览次数:42  
标签:OpenID Postman server access token your authorization


This post is the eighth part of a series of blog posts entitled Creating your own OpenID Connect server with ASOS:

  1. Introduction
  2. Choosing the right flow(s)
  3. Registering the middleware in the ASP.NET Core pipeline
  4. Creating your own authorization provider
  5. Implementing the resource owner password credentials grant
  6. Implementing the authorization code and implicit flows
  7. Adding custom claims and granting scopes
  8. Testing your authorization server with Postman
  9. Conclusion

The sample used in this post can be found in the AspNet.Security.OpenIdConnect.Samples repository, that also hosts the Cordova, MVC and SignalR samples for ASOS.

For clarity, it implements both the authorization code flow and the password flow, but doesn't use any membership stack (the user credentials are hardcoded in the authorization provider class and a fake identity is always used to create tokens).

To test REST services, one of the easiest options is indisputably to use Postman. If you're not already familiar with Postman, I encourage you to read the documentation.


Retrieving an access token using the resource owner password credentials grant

Using the password flow with Postman is quite straightforward:

  • Select POST as the HTTP method.
  • Fill the Request URL input with the absolute address of the token endpoint.
  • Click on the Body tab and choose the x-www-form-urlencoded encoding.
  • Add the OAuth2 parameters required by the specification, as shown on this screenshot:
1
2
3
4
5
POST /connect/token HTTP/1.1
Host: localhost:6500
Content-Type: application/x-www-form-urlencoded

grant_type=password&password=P%40ssw0rd&username=Bob&scope=openid+offline_access

If your request is valid, an access token, an identity token and a refresh token should be returned:

While the access token and the refresh token are encrypted and opaque for the client, the identity token can be easily deserialized using a tool like jwt.io:


Making an API request using the access token issued by ASOS

To attach an access token to an API request, click on the Headers tab and add a new Authorization header. Make sure to prefix the header value with the Bearer scheme (plus a space separating the scheme and the access token).

1
2
3
GET /api/message HTTP/1.1
Host: localhost:6500
Authorization: Bearer CfDJ8CreAGYABzhAplxF9ZB11h_KUDCvbaypmh1sSTXrF4vxzxUwINdmwkmXBuDASGNZ6_buqhTKjWcVexE0KweZzwuHAMG_lo4ZGuSo3max4uG95m302E0xH6KZSecfZYBa_1jUUbknCS46jEH0pwuJzG4hCnLTdzH3x8Q32OzpnXB1pPhJts1Xz4XNUdmNYuP0m8Pi2n37eqjbmZjCYnLdaQYQNNEGTU6FkvWyuvDo401Tt5fvpCWE0DIu_99Cotu5eYzDQPnS3AAD96PfKYt24DRacUW9x3NPxMToR7b3aUN7-lZm_mccU-uxapTuIwzl5SuXSYeFJmgkbRU8ub4W2M1n3o0n2DToKiOO1n0t9EEFdk6Q9ky6B2MdIilAibNcx0o3fz2xnIirGYP831lxWAf0plr502t5fNqNTQEINd4kqWFRXVfpBZ6ZZVvzcJPV8B9HNKdpQiJGqmqqWj_NK7IedZcGY1dH6LAo_JDuiTet3jlLQlY_5MvZ0z-QYg1JARRuW8qFhgE_G0x8nwLUWRdphtp1OYNDYbYhS2gn_uuRJcG9cGsOOXoYlnYdtJI1NZHL-fXDXIw6J4RvXsv2hE_pzYZl26XhMACVa5lTx4v0D49uwlKFp0OB3OCI_Wbxq2zAnemdo7nnZcsdkgiUGHhMC6c_6EN71mJG-GYqU9Nl

If the access token is still valid, you should see this exact output message:


Retrieving an access token using the authorization code flow

Using the authorization code flow is generally more complicated, but Postman offers a very simple and convenient way to retrieve an access token without having to write a single request.

To start a new authorization flow, click on the Authorization tab, select OAuth 2.0 and press Get new access token:

When the OAuth 2.0 configuration popup appears, select Authorization code in the dropdown list and populate the required fields by specifying the authorization endpoint, the token endpoint, the client identifier, the callback URL and optionally, a scope and a token name.

When running the sample from a location that is not accessible from Internet, make sure to check the Request access token locally checkbox.

If the request parameters are valid, you should be prompted by the authorization consent form returned by AuthorizationController:

After granting the authorization, Postman will send a token request and retrieve a new access token it will add under the Existing tokens list:

Select Header in the dropdown list and press Use token to tell Postman to attach the access token to the API request, like you manually did in the previous step. If the token is still valid, clicking on Send will return a successful message:


Next part: Conclusion.

ShareComments NEWER Creating your own OpenID Connect server with ASOS: conclusion OLDER Creating your own OpenID Connect server with ASOS: adding custom claims and granting scopes     转 https://kevinchalet.com/2016/07/13/creating-your-own-openid-connect-server-with-asos-testing-your-authorization-server-with-postman/   搜索 @@openiddict The 'client_secret' parameter is not valid for this client application.   @@OpenIddict postman grant_type password     #Creating your own OpenID Connect server with ASOS: testing your authorization server with Postman

标签:OpenID,Postman,server,access,token,your,authorization
From: https://www.cnblogs.com/wl-blog/p/17416050.html

相关文章

  • 2017年全国大学生信息安全竞赛---wanna to see your hat?
    ======================================个人收获:1.SQL注入语句中用/**/代替空格  (虽然之前就知道)    =========================================  题目界面:  常规的点击连接查看页面看到接下来几个页面 没有什么特别的发现,同时也查看了网页的源码也没有什么发现。......
  • SQL server 备份job堵塞查询
    SELECTreq.session_id,database_name=db_name(req.database_id),req.status,req.blocking_session_id,req.command,[sql_text]=Substring(txt.TEXT,(req.statement_start_offset/2)+1,((CASEreq.statement_end_offsetWHEN-1THENDatalength(txt.TEXT)......
  • SQL SERVER PROFILER
    首先我需要查询出需要使用SQLServerProfiler跟踪的数据库标识ID,若不知道怎么查询数据库的标识ID, 打开SQLServermanagementstudio,点击工具。选择SQLServerProfiler。 登录,登录成功后,如果有个默认弹窗,先取消 新建追踪 命名  ......
  • SqlServer查询锁表及解锁
    --查询锁表进程selectrequest_session_idspid,OBJECT_NAME(resource_associated_entity_id)tableNamefromsys.dm_tran_lockswhereresource_type='OBJECT'--解锁进程declare@spidintSet@spid=162--锁表进程declare@sqlvarchar(1000)set@sql='kill......
  • 上海丨阿里云 Serverless 技术实战营邀你来玩!
    活动简介本次沙龙深度探讨“Serverless在中国企业的落地和开发者实操”主题,我们特别邀请了来自阿里云一线技术专家,分享当前Serverless趋势和落地实践过程中的挑战和机遇;带来数据库Serverless技术架构及应用实践;浅析云原生时代开发者需要的Serverless能力,为开发者日常......
  • ZCL_REST_SERVER
    IntroductionHistoryPublicMethodIF_HTTP_EXTENSION~HANDLE_REQUESTProtectedMethod_HANDLE_REQUESTSample建立RESTful-APIClass設定API路徑LogsAppendixSMICM各環境HostName,PortIntroductionZCL_REST_SERVERRESTful-APIproviderenhanceme......
  • MS SQL Server 排查阻塞和查找被锁语句
    --方法1SELECT'资源类型'=t1.resource_type,'来源数据库'=CONVERT(CHAR(25),DB_NAME(resource_database_id)),'数据库中与资源相关联的实体的ID'=t1.resource_associated_entity_id,'锁模式'=t1.request_mode, --锁的模式:S-共享锁,U-更新锁,X-排他锁,IS/IU/IX-意向......
  • 泛微CheckServer.jsp注入
    /mobile/plugin/CheckServer.jsp通过urldecode可以绕过泛微waf......
  • 什么是 Angular 应用的 browser Application bundles 和 server Application bundle
    我们在使用yarnrun启动Angular应用时,注意到browserApplication和serverApplicationbundle的生成:在Angular应用程序中,应用程序包含两个主要的部分:客户端应用程序和服务器应用程序。客户端应用程序是在Web浏览器中运行的Angular应用程序,而服务器应用程序是在服......
  • ASP.NET Core Swagger接入使用IdentityServer4 的 WebApi
    写在前面是这样的,我们现在接口使用了Ocelot做网关,Ocelot里面集成了基于IdentityServer4的开发的授权中心用于对Api资源的保护。问题来了,我们的Api用了SwaggerUI做接口的自文档,那就蛋疼了,你接入了IdentityServer4的Api,用SwaggerUI调试、调用接口的话,妥妥的401,未授权啊。那有小伙伴就......