Swashbuckle.aspnetcore: x-tokenName Support

Created on 16 Apr 2019  路  2Comments  路  Source: domaindrivendev/Swashbuckle.AspNetCore

Is there a way to set the x-tokenName present in the ui through the server?

Here's a snippit of the minified code

```var o = r.token
, i = r.value || r
, u = g[n]
, s = u.type
, l = u["x-tokenName"] || "access_token"
, f = o && o[l]
, d = o && o.token_type;

I try to set this manually in the security definition but it doesn't work correctly.

I need to extract the `id_token` from the string that comes back from the authentication server, not the `access_token`

Here's my configuration:
```c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme()
{
    Description = "Cognito Authentication",
    Extensions = new Dictionary<string, IOpenApiExtension>
    {
        { "x-tokenName", new OpenApiString("id_token") }
    },
    Flows = new OpenApiOAuthFlows()
    {
        Implicit = new OpenApiOAuthFlow()
        {
            AuthorizationUrl = configuration.AuthorizationUrl,
            TokenUrl = configuration.TokenUrl,
            Scopes = new Dictionary<string, string>()
            {
                { "openid", "openid token" }
            },
        },
    },
    Name = "Authorization",
    In = ParameterLocation.Header,
    Type = SecuritySchemeType.OAuth2,
});

c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
    {
        new OpenApiSecurityScheme
        {
            Extensions = new Dictionary<string, IOpenApiExtension>
            {
                {"x-tokenName", new OpenApiString("id_token") }
            },
            Reference = new OpenApiReference
            {
                Type = ReferenceType.SecurityScheme,
                Id = "oauth2"
            },
        },
        new List<string>()
    }
});

Most helpful comment

@domaindrivendev can we get swaggerui's npm packaged up'd to version 3.25.0 and pushed to nuget?
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/src/Swashbuckle.AspNetCore.SwaggerUI/package.json

they have now released the fixed for swagger client here:
https://github.com/swagger-api/swagger-js/pull/1489#issuecomment-576952682

and the swagger ui here:
https://github.com/swagger-api/swagger-ui/issues/4084#issuecomment-576330645

All 2 comments

This is a swagger-ui issue and should be submitted to that project instead of Swashbuckle. In fact, it looks like someone has already done that - https://github.com/swagger-api/swagger-ui/issues/4084

@domaindrivendev can we get swaggerui's npm packaged up'd to version 3.25.0 and pushed to nuget?
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/src/Swashbuckle.AspNetCore.SwaggerUI/package.json

they have now released the fixed for swagger client here:
https://github.com/swagger-api/swagger-js/pull/1489#issuecomment-576952682

and the swagger ui here:
https://github.com/swagger-api/swagger-ui/issues/4084#issuecomment-576330645

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TimmyGilissen picture TimmyGilissen  路  3Comments

jderus picture jderus  路  4Comments

engelhardtda picture engelhardtda  路  3Comments

vanillajonathan picture vanillajonathan  路  3Comments

voroninp picture voroninp  路  3Comments