add keycloak auth
This commit is contained in:
parent
d3f2b5ad44
commit
6b4baadcae
|
|
@ -19,12 +19,14 @@
|
|||
|
||||
<ItemGroup>
|
||||
|
||||
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.2" />
|
||||
<PackageReference Include="AspNet.Security.OAuth.GitHub" Version="8.0.0" />
|
||||
<PackageReference Include="AspNet.Security.OAuth.Keycloak" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
|
@ -32,6 +34,7 @@
|
|||
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="6.0.27" />
|
||||
<PackageReference Include="AspNet.Security.OAuth.GitHub" Version="6.0.15" />
|
||||
<PackageReference Include="AspNet.Security.OAuth.Keycloak" Version="6.0.15" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.25" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.26" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -101,6 +101,21 @@ public static class BotSharpOpenApiExtensions
|
|||
});
|
||||
}
|
||||
|
||||
// Keycloak Identiy OAuth
|
||||
if (!string.IsNullOrWhiteSpace(config["OAuth:Keycloak:ClientId"]) && !string.IsNullOrWhiteSpace(config["OAuth:Keycloak:ClientSecret"]))
|
||||
{
|
||||
builder = builder.AddKeycloak(options =>
|
||||
{
|
||||
options.BaseAddress = new Uri(config["OAuth:Keycloak:BaseAddress"]);
|
||||
options.Realm = config["OAuth:Keycloak:Realm"];
|
||||
options.ClientId = config["OAuth:Keycloak:ClientId"];
|
||||
options.ClientSecret = config["OAuth:Keycloak:ClientSecret"];
|
||||
options.AccessType = AspNet.Security.OAuth.Keycloak.KeycloakAuthenticationAccessType.Confidential;
|
||||
int version = Convert.ToInt32(config["OAuth:Keycloak:Version"]??"22") ;
|
||||
options.Version = new Version(version,0);
|
||||
});
|
||||
}
|
||||
|
||||
// Add services to the container.
|
||||
services.AddControllers()
|
||||
.AddJsonOptions(options =>
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ public class UserController : ControllerBase
|
|||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("/sso/{provider}")]
|
||||
public async Task<IActionResult> Authorize([FromRoute] string provider)
|
||||
public async Task<IActionResult> Authorize([FromRoute] string provider,string redirectHost)
|
||||
{
|
||||
return Challenge(new AuthenticationProperties { RedirectUri = $"page/user/me" }, provider);
|
||||
return Challenge(new AuthenticationProperties { RedirectUri = $"{redirectHost}/page/user/me" }, provider);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
|
|
|||
|
|
@ -21,6 +21,13 @@
|
|||
"Google": {
|
||||
"ClientId": "",
|
||||
"ClientSecret": ""
|
||||
},
|
||||
"Keycloak": {
|
||||
"BaseAddress": "",
|
||||
"Realm": "",
|
||||
"ClientId": "",
|
||||
"ClientSecret": "",
|
||||
"Version": 22
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue