Web Api found ...
This commit is contained in:
parent
3df1c1b14d
commit
1d6cad7bef
23 changed files with 215 additions and 870 deletions
|
|
@ -54,14 +54,31 @@ namespace testOauthClient.Controllers
|
|||
public async Task<IActionResult> GetUserInfo(CancellationToken cancellationToken)
|
||||
{
|
||||
var accessToken = await HttpContext.GetTokenAsync("access_token");
|
||||
var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
|
||||
var client = new HttpClient(new HttpClientHandler(){ AllowAutoRedirect=false });
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
var content = await client.GetStringAsync("https://localhost:5001/api/account/me");
|
||||
var obj = JsonSerializer.Deserialize<JsonElement>(content);
|
||||
client.SetBearerToken(accessToken);
|
||||
var content = await client.GetAsync("https://localhost:5001/api/account/me");
|
||||
content.EnsureSuccessStatusCode();
|
||||
var json = await content.Content.ReadAsStreamAsync();
|
||||
var obj = JsonSerializer.Deserialize<JsonElement>(json);
|
||||
return View("UserInfo", obj.ToString());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> GetApiCall(CancellationToken cancellationToken)
|
||||
{
|
||||
var accessToken = await HttpContext.GetTokenAsync("access_token");
|
||||
var client = new HttpClient(new HttpClientHandler(){ AllowAutoRedirect=false });
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
client.SetBearerToken(accessToken);
|
||||
var content = await client.GetAsync("https://localhost:6001/identity");
|
||||
content.EnsureSuccessStatusCode();
|
||||
var json = await content.Content.ReadAsStreamAsync();
|
||||
var obj = JsonSerializer.Deserialize<JsonElement>(json);
|
||||
return View("UserInfo", obj.ToString());
|
||||
}
|
||||
|
||||
|
||||
public IActionResult About()
|
||||
{
|
||||
ViewData["Message"] = "Your application description page.";
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:16967",
|
||||
"sslPort": 44387
|
||||
"applicationUrl": "http://localhost:5002",
|
||||
"sslPort": 5003
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5164",
|
||||
"applicationUrl": "http://localhost:5002",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7055;http://localhost:5164",
|
||||
"applicationUrl": "https://localhost:5003;http://localhost:5002",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ public class Startup
|
|||
.AddOpenIdConnect("Yavsc", options =>
|
||||
{
|
||||
options.Authority = "https://localhost:5001";
|
||||
|
||||
options.ClientId = "mvc";
|
||||
options.ClientSecret = "49C1A7E1-0C79-4A89-A3D6-A37998FB86B0";
|
||||
options.ResponseType = "code";
|
||||
|
|
@ -32,6 +31,8 @@ public class Startup
|
|||
options.Scope.Add("openid");
|
||||
options.Scope.Add("profile");
|
||||
options.Scope.Add("email");
|
||||
options.Scope.Add("offline_access");
|
||||
options.Scope.Add("scope2");
|
||||
|
||||
options.GetClaimsFromUserInfoEndpoint = true;
|
||||
options.SaveTokens = true;
|
||||
|
|
@ -44,6 +45,7 @@ public class Startup
|
|||
NameClaimType = "name",
|
||||
RoleClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
|
||||
};
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@
|
|||
<form action="~/Home/GetUserInfo" method="post">
|
||||
<button class="btn btn-lg btn-warning" type="submit">Get user info</button>
|
||||
</form>
|
||||
|
||||
<form action="~/Home/GetApiCall" method="post">
|
||||
<button class="btn btn-lg btn-warning" type="submit">Api Call</button>
|
||||
</form>
|
||||
|
||||
<form action="~/Home/PostDeviceInfo" method="post">
|
||||
<button class="btn btn-lg btn-warning" type="submit">Post device info</button>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yavsc.Abstract\Yavsc.Abstract.csproj" />
|
||||
<PackageReference Include="IdentityModel.AspNetCore" Version="4.3.0" />
|
||||
<PackageReference Include="IdentityModel.AspNetCore" Version="4.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.12" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -10,6 +11,7 @@
|
|||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue