增加 IdentityModel.OidcClient 测试ok
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
using Amazon.Auth.AccessControlPolicy;
|
||||
using Amazon.SecurityToken;
|
||||
using Azure.Core;
|
||||
using IdentityModel.Client;
|
||||
using IdentityModel.OidcClient;
|
||||
using IRaCIS.Application.Contracts;
|
||||
using IRaCIS.Application.Interfaces;
|
||||
using IRaCIS.Core.API.OAuth;
|
||||
using IRaCIS.Core.Application.Auth;
|
||||
using IRaCIS.Core.Application.Contracts;
|
||||
using IRaCIS.Core.Application.Helper;
|
||||
@@ -25,7 +26,9 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
using AssumeRoleRequest = Amazon.SecurityToken.Model.AssumeRoleRequest;
|
||||
@@ -433,63 +436,6 @@ namespace IRaCIS.Api.Controllers
|
||||
#endregion
|
||||
|
||||
|
||||
#region 客户端方式获取logto 里面的信息
|
||||
|
||||
var baseUrl = "https://logto.test.extimaging.com";
|
||||
var appId = "v2mr2ndxwkxz0xpsuc1th";
|
||||
var appSecret = "yq9jUxl70QoOmwHxJ37h1rDoyJ5iz92Q";
|
||||
var apiAddress = "https://default.logto.app/api"; //这里是个坑
|
||||
var scope = "all";
|
||||
|
||||
var opts = new RestClientOptions(baseUrl);
|
||||
using var client = new RestClient(opts);
|
||||
|
||||
//https://bump.sh/logto/doc/logto-management-api/authentication
|
||||
var request = new RestRequest("oidc/token", Method.Post);
|
||||
request
|
||||
.AddHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
.AddParameter("grant_type", "client_credentials")
|
||||
.AddParameter("client_id", appId)
|
||||
.AddParameter("client_secret", appSecret)
|
||||
.AddParameter("resource", apiAddress) //注意这里默认值地址和api 地址有区别
|
||||
.AddParameter("scope", scope);
|
||||
|
||||
|
||||
var response = await client.ExecuteAsync<LogtoTokenResponse>(request);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var tokenResponse = response.Data;
|
||||
|
||||
Console.WriteLine(tokenResponse.ToJsonStr());
|
||||
|
||||
#region 获取应用信息
|
||||
|
||||
var applicationRequest = new RestRequest($"/api/applications", Method.Get)
|
||||
.AddHeader("Authorization", $"Bearer {tokenResponse.AccessToken}");
|
||||
|
||||
var applicationResponse = await client.ExecuteAsync(applicationRequest);
|
||||
#endregion
|
||||
|
||||
#region 获取用户信息
|
||||
//curl \
|
||||
// -X GET https://[tenant_id].logto.app/api/users/{userId} \
|
||||
// -H "Authorization: Bearer $ACCESS_TOKEN"
|
||||
|
||||
var userId = "4fqx4cb3438k";
|
||||
var userInfoRequest = new RestRequest($"api/users/{userId}", Method.Get)
|
||||
.AddHeader("Authorization", $"Bearer {tokenResponse.AccessToken}");
|
||||
|
||||
|
||||
var userResponse = await client.ExecuteAsync<LogtoUser>(userInfoRequest);
|
||||
|
||||
Console.WriteLine(userResponse.Content);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
|
||||
Reference in New Issue
Block a user