Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@

<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>

<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>
Expand Down
15 changes: 15 additions & 0 deletions src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ public static IServiceCollection AddBotSharpOpenAPI(this IServiceCollection serv
});
}

// 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 =>
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the name to redirectUrl ? And add the [FromQuery] annotation.

Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public async Task<ActionResult<Token>> GetToken([FromHeader(Name = "Authorizatio

[AllowAnonymous]
[HttpGet("/sso/{provider}")]
public async Task<IActionResult> Authorize([FromRoute] string provider)
public async Task<IActionResult> Authorize([FromRoute] string provider,string redirectUrl)
{
return Challenge(new AuthenticationProperties { RedirectUri = $"page/user/me" }, provider);
return Challenge(new AuthenticationProperties { RedirectUri = redirectUrl }, provider);
}

[AllowAnonymous]
Expand Down
7 changes: 7 additions & 0 deletions src/WebStarter/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
"Google": {
"ClientId": "",
"ClientSecret": ""
},
"Keycloak": {
"BaseAddress": "",
"Realm": "",
"ClientId": "",
"ClientSecret": "",
"Version": 22
}
},

Expand Down