Replies: 3 comments
-
Is anyone able to confirm if this SHOULD work? |
Beta Was this translation helpful? Give feedback.
-
Using Fiddler, I found that the request to the token Url was using an "OPTIONS" verb. Not sure yet how to make it POST and with correct content.
|
Beta Was this translation helpful? Give feedback.
-
This is an example of how eneable Oauth2 authentification on SwaggerUI, using .net 9 and open api 3, with Azure Entra ID : using NSwag;
using NSwag.Generation.Processors.Security;
using Microsoft.AspNetCore.Builder;
public void AddApiDocumentation(IServiceCollection services)
{
services.AddOpenApiDocument(document =>
{
document.AddSecurity("OAuth2", Enumerable.Empty<string>(), new OpenApiSecurityScheme
{
Type = OpenApiSecuritySchemeType.OAuth2,
Description = "OAuth2 - authentification via Azure AD App Registration",
Flows = new OpenApiOAuthFlows()
{
AuthorizationCode = new OpenApiOAuthFlow()
{
AuthorizationUrl = "https://login.microsoftonline.com/<TenantId>/oauth2/v2.0/authorize",
TokenUrl = "https://login.microsoftonline.com/<TenantId>/oauth2/v2.0/token",
Scopes = {
{ "<clientId>/scope1", "description" },
{ "<clientId>/App.Read", "another scope" },
} ,
}
}
});
document.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("OAuth2"));
});
}
public virtual void UseApiDocumentation(IApplicationBuilder app)
{
app.UseOpenApi();
app.UseSwaggerUi(settings =>
{
settings.OAuth2Client = new NSwag.AspNetCore.OAuth2ClientSettings
{
ClientId = <clientId>, //app registration Identity specific for swagger
ClientSecret = "", // no secret
UsePkceWithAuthorizationCodeGrant = true,
};
});
}
// Then in your program.cs
var builder = WebApplication.CreateBuilder(args);
//...
AddApiDocumentation(builder.Services);
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
UseApiDocumentation(app);
} More useful information on how to full setup (using AzureAD) on this video : https://www.youtube.com/watch?v=0S0aspQAxrc |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using NSwag.AspNetCore v14.0.3 have followed this to help me setup Authorisation using Client Credentials flow
This is what my code looks like:
When I use and click the "Authorize" button, I am presented this

When I fill out a clientid and secret and click the authorize button I get a 400

And if I have a look at the payload I can see that it most definitely is missing

It should show as a minimum
Am I missing something? Is this not possible?
Beta Was this translation helpful? Give feedback.
All reactions