I installed the meta-package Swashbuckle.AspNetCore, and following the examples given have stumbled upon this missing class.
I have tried installing each library manually, changing from 5.0.0-rc2 to rc1 and beta. I tried 4.0.1 but had many errors. I tried to find the class in your source code with no luck, have tried googling around but they are only copy pastes of your example configuration code.
Nobody seems to have the same issue as I am, so I must have missed something obvious. Can anyone point me in the right direction?
I made my own "OAuth2Scheme" class to try and continue. While I've got it all compiling, it seems to cause javascript errors when looking for an "entrySeq" property.
public class OAuth2Scheme : OpenApiSecurityScheme
{
public string Flow { get; set; }
public string AuthorizationUrl { get; set; }
public Dictionary<string, string> Scopes { get; set; }
}
And this is basically trying to follow the documentation but it seems like a few things have changed...
var securityScheme = new OAuth2Scheme
{
Type = SecuritySchemeType.OAuth2, //"oauth2",
Flow = "implicit",
AuthorizationUrl = "url removed",
Scopes = new Dictionary<string, string>
{
{"readAccess", "Access read operations"},
{"writeAccess", "Access write operations"}
}
};
c.AddSecurityDefinition("oauth2", securityScheme);
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{securityScheme, new List<string>{ "readAccess", "writeAccess"} }
});
With the above code, I try loading the swaggerui and receive a
馃槺 Could not render this component, see the console.
In the console
swagger-ui-bundle.js:70 TypeError: Cannot read property 'entrySeq' of undefined
at swagger-ui-bundle.js:70
at swagger-ui-bundle.js:1
at swagger-ui-bundle.js:1
at swagger-ui-bundle.js:1
at swagger-ui-bundle.js:1
at pt.__iterate (swagger-ui-bundle.js:1)
at Pt.__iterate (swagger-ui-bundle.js:1)
at Nt.__iterate (swagger-ui-bundle.js:1)
at r.__iterateUncached (swagger-ui-bundle.js:1)
at le (swagger-ui-bundle.js:1)
Also I hesitate to ask for advice in an issue but its a quick question: Is it normal to share a ClientId and ClientSecret to a 3rd party to authorize with my API? Using Auth0 and it seems to be the only way.
Hi @InntecDeveloper,
Can you show which errors are you getting when adding the 4.0.1 version?
Regards,
脌lex.
Apologies, but when reinstalling the 4.0.1 version the errors I was seeing before are no longer there. It could have been something out of whack with my IDE.
Regardless, I still have the issue of the missing "OAuth2Scheme" class. Creating my own didn't work, and I cannot find any information on the class or where it comes from so I am dead in the water. Everything else works fine, so I just left it alone.
I have the same issue even with 5.0.0-rc4. Does anyone have an idea ?
I found the solution. You have to use the OpenApiSecurityScheme class :
```// Startup.cs
services.AddSwaggerGen(c =>
{
...
// Define the OAuth2.0 scheme that's in use (i.e. Implicit Flow)
c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
{
Implicit = new OpenApiOAuthFlow
{
AuthorizationUrl = new Uri("/auth-server/connect/authorize", UriKind.Relative),
Scopes = new Dictionary<string, string>
{
{ "readAccess", "Access read operations" },
{ "writeAccess", "Access write operations" }
}
}
}
});
};```
Most helpful comment
I found the solution. You have to use the OpenApiSecurityScheme class :
```// Startup.cs
services.AddSwaggerGen(c =>
{
...
};```