日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

ASP.NET Core分布式项目实战(第三方ClientCredential模式调用)--学习笔记

發布時間:2023/12/4 asp.net 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP.NET Core分布式项目实战(第三方ClientCredential模式调用)--学习笔记 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

任務10:第三方ClientCredential模式調用

創建一個控制臺程序

dotnet new console --name ThirdPartyDemo

添加 Nuget 包:IdentityModel

添加之后還原

dotnet restore

Client

using System; using System.Net.Http; using System.Threading.Tasks; using IdentityModel.Client; using Newtonsoft.Json.Linq;namespace ThirdPartyDemo {class Program{static async Task Main(string[] args){// discover endpoints from metadatavar client = new HttpClient();var disco = client.GetDiscoveryDocumentAsync("http://localhost:5000").Result;if (disco.IsError){Console.WriteLine(disco.Error);return;}// request tokenvar tokenResponse = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest{Address = disco.TokenEndpoint,ClientId = "client",ClientSecret = "secret",Scope = "api"});if (tokenResponse.IsError){Console.WriteLine(tokenResponse.Error);return;}Console.WriteLine(tokenResponse.Json);// call apivar client2 = new HttpClient();client2.SetBearerToken(tokenResponse.AccessToken);var response = await client2.GetAsync("http://localhost:5001/weatherforecast");if (!response.IsSuccessStatusCode){Console.WriteLine(response.StatusCode);}else{var content = await response.Content.ReadAsStringAsync();Console.WriteLine(JArray.Parse(content));}}} }

先啟動 IdentityServerCenter,ClientCredentialApi

再啟動 ThirdPartyDemo,輸出如下:

{"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImZFd0d5VGQtY2FkaE9Oamp6ajc5THciLCJ0eXAiOiJhdCtqd3QifQ.eyJuYmYiOjE1ODYyNzcwNTYsImV4cCI6MTU4NjI4MDY1NiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo1MDAwIiwiYXVkIjoiYXBpIiwiY2xpZW50X2lkIjoiY2xpZW50Iiwic2NvcGUiOlsiYXBpIl19.KRgYum2zuAdqNkzm9rMfIh7ARMPJHLZw_k55AU-wxQEYfhc6ZAiJkayRY98gKJb--nvblpBTE4u5erJNUSBBGXriMsohemvVh-8pA72PkVzNJ9KuDAUX3VagsphQ36-ZEf7lq1V87y0Fh3higUsFTeyEa8D1pZQncS6GzlRel-Q7ghX20tVl0pWdvN1BnG06AdU9-1l15OoKg9aDRL9oKf4MO9zvJhJhmXazigvrWTKEcTk7gUVs-NW8rxBwNagTC386vVSatd5qmAhph4eDA8Ryjf9utE8qEDD6cuX2qFJn0yKxpFm2zn9AMUs5YmKMesUddKeocdk9DAIXIdqehw","expires_in": 3600,"token_type": "Bearer","scope": "api" } [{"date": "2020-04-09T00:30:56.3318938+08:00","temperatureC": -12,"temperatureF": 11,"summary": "Hot"},{"date": "2020-04-10T00:30:56.3328057+08:00","temperatureC": 2,"temperatureF": 35,"summary": "Cool"},{"date": "2020-04-11T00:30:56.3328097+08:00","temperatureC": 27,"temperatureF": 80,"summary": "Sweltering"},{"date": "2020-04-12T00:30:56.33281+08:00","temperatureC": 35,"temperatureF": 94,"summary": "Balmy"},{"date": "2020-04-13T00:30:56.3328102+08:00","temperatureC": 23,"temperatureF": 73,"summary": "Mild"} ]

參考文檔:

http://docs.identityserver.io/en/latest/quickstarts/1_client_credentials.html#creating-the-client

課程鏈接

http://video.jessetalk.cn/course/explore

相關文章

ASP.NET Core分布式項目實戰(客戶端集成IdentityServer)--學習筆記

ASP.NET Core分布式項目實戰(業務介紹,架構設計,oAuth2,IdentityServer4)--學習筆記

ASP.NET Core分布式項目實戰(課程介紹,MVP,瀑布與敏捷)--學習筆記

ASP.NET Core快速入門 -- 學習筆記匯總

總結

以上是生活随笔為你收集整理的ASP.NET Core分布式项目实战(第三方ClientCredential模式调用)--学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。