You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using IdentityModel;
|
|
|
|
|
using IdentityModel.Jwk;
|
|
|
|
|
using IdentityModel.Client;
|
|
|
|
|
using IdentityModel.Internal;
|
|
|
|
|
|
|
|
|
|
namespace Id4Study.Test
|
|
|
|
|
{
|
|
|
|
|
public class UnitTest1
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Test1Async()
|
|
|
|
|
{
|
|
|
|
|
var client = new HttpClient();
|
|
|
|
|
|
|
|
|
|
DiscoveryDocumentRequest discoveryDocumentRequest = new DiscoveryDocumentRequest()
|
|
|
|
|
{
|
|
|
|
|
Policy = new DiscoveryPolicy() { RequireHttps = false},
|
|
|
|
|
Address = "http://192.168.20.46:8017/",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//发现文档
|
|
|
|
|
var disco = await client.GetDiscoveryDocumentAsync(discoveryDocumentRequest, CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
Assert.False(disco.IsError);
|
|
|
|
|
|
|
|
|
|
// 请求令牌
|
|
|
|
|
var tokenResponse = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
|
|
|
|
|
{
|
|
|
|
|
Address = disco.TokenEndpoint,
|
|
|
|
|
|
|
|
|
|
ClientId = "edit_oa",
|
|
|
|
|
ClientSecret = "edit_oa",
|
|
|
|
|
Scope = "EDS.Editor.WebAPI.Plan EDS.Editor.WebAPI.Scene EDS.Editor.WebAPI.Member EDS.Editor.WebAPI.Common EDS.Editor.WebAPI.Resource EDS.Editor.WebAPI.Exam"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Assert.False(tokenResponse.IsError);
|
|
|
|
|
|
|
|
|
|
//访问WebAPI
|
|
|
|
|
//tokenResponse.AccessToken;
|
|
|
|
|
|
|
|
|
|
client.SetBearerToken(tokenResponse?.AccessToken ?? "");
|
|
|
|
|
|
|
|
|
|
HttpResponseMessage? res = await client.GetAsync(
|
|
|
|
|
"http://192.168.20.46:8016/api.exam/v1.0.0.0/Paper/GetPaperListByPage?companyId=1051&orgId=198¤tPageIndex=1&pageSize=50");
|
|
|
|
|
|
|
|
|
|
Assert.True(res.IsSuccessStatusCode);
|
|
|
|
|
|
|
|
|
|
var content = await res.Content.ReadAsStringAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|