title: Swagger Authorization with Okta configuration JWT token
body: <p>I am trying to authorize the swagger api with the okta configuration using ASP.NET core 2.2.</p>
  
  <p>Followed the instruction from this link
  <a href="https://app.swaggerhub.com/help/enterprise/user-management/sso/okta" rel="nofollow noreferrer">https://app.swaggerhub.com/help/enterprise/user-management/sso/okta</a></p>
  
  <p>But quite not sure how can I do it.</p>
  
  <p>Okta link </p>
  
  <p><a href="https://developer.okta.com/quickstart/?_ga=2.180885607.1554519477.1569975022-1481902663.1569975022#/angular/dotnet/aspnetcore" rel="nofollow noreferrer">https://developer.okta.com/quickstart/?_ga=2.180885607.1554519477.1569975022-1481902663.1569975022#/angular/dotnet/aspnetcore</a></p>
  
  <p>here is my Asp.net code </p>
  
  <pre><code>ConfigureSwagger(services);
  
  protected virtual void ConfigureSwagger(IServiceCollection services)
          {
              // to view online help, goto ~/swagger/
              services.AddTransient&lt;IConfigureOptions&lt;SwaggerGenOptions&gt;, ConfigureSwaggerOptions&gt;();
  
              services.AddSwaggerGen(options =&gt;
              {
                  // add a custom operation filter which sets default values
                  options.OperationFilter&lt;SwaggerDefaultValues&gt;();
              });
              services.ConfigureSwaggerGen(options =&gt; { });
          }
  
  
   public class ConfigureSwaggerOptions : IConfigureOptions&lt;SwaggerGenOptions&gt;
      {
          readonly IApiVersionDescriptionProvider provider;
  
          /// &lt;summary&gt;
          /// Initializes a new instance of the &lt;see cref="ConfigureSwaggerOptions"/&gt; class.
          /// &lt;/summary&gt;
          /// &lt;param name="provider"&gt;The &lt;see cref="IApiVersionDescriptionProvider"&gt;provider&lt;/see&gt; used to generate Swagger documents.&lt;/param&gt;
          public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) =&gt; this.provider = provider;
  
          /// &lt;inheritdoc /&gt;
          public void Configure(SwaggerGenOptions options)
          {
              // add a swagger document for each discovered API version
              // note: you might choose to skip or document deprecated API versions differently
              foreach (var description in provider.ApiVersionDescriptions)
              {
                  options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description));
              }
  
              options.OrderActionsBy(apiDesc =&gt; apiDesc.RelativePath);
  
              options.IncludeXmlComments(Path.ChangeExtension(typeof(Startup).GetTypeInfo().Assembly.Location, "xml"));
              options.DescribeAllEnumsAsStrings();
              options.DescribeStringEnumsInCamelCase();
  
              //options.AddSecurityDefinition("oauth2",
              //    new OAuth2Scheme
              //    {
              //        Type = "oauth2",
              //        Flow = "implicit",
              //        AuthorizationUrl = new Uri("/connect/authorize", UriKind.Relative).ToString(),
              //        Scopes = new Dictionary&lt;string, string&gt;
              //        {
              //            {"api1", "DEMO API"}
              //        }
              //    });
  
              //options.AddSecurityRequirement(new[] { "oauth2", "api1" });
  
              options.AddSecurityDefinition("oauth2",
                  new OpenApiSecurityScheme
                  {
                      Type = SecuritySchemeType.OAuth2,
  
                      Flows = new OpenApiOAuthFlows
                      {
                          Implicit = new OpenApiOAuthFlow
                          {
                              AuthorizationUrl = new Uri("/connect/authorize", UriKind.Relative),
                              Scopes = new Dictionary&lt;string, string&gt;
                              {
                                  {Program.ResourceIdentifier, Program.ApplicationName}
                              }
                          }
                      }
                  });
  
              options.AddSecurityRequirement(new OpenApiSecurityRequirement
              {
                  {
                      new OpenApiSecurityScheme
                      {
                          Reference = new OpenApiReference
                          {
                              Type = ReferenceType.SecurityScheme,
                              Id = "oauth2"
                          }
                      },
                      new[] {"oauth2", Program.ResourceIdentifier }
                  }
              });
  
              options.EnableAnnotations();
  
              //options.DocInclusionPredicate((docName, apiDesc) =&gt;
              //{
              //    if (!apiDesc.TryGetMethodInfo(out MethodInfo methodInfo)) return false;
  
              //    var versions = methodInfo.DeclaringType
              //        .GetCustomAttributes(true)
              //        .OfType&lt;ApiVersionAttribute&gt;()
              //        .SelectMany(attr =&gt; attr.Versions);
  
              //    return versions.Any(v =&gt; $"v{v.ToString()}" == docName);
              //});
          }
  
          static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description)
          {
              var info = new OpenApiInfo
              {
                  Title = Program.ApplicationName,
                  Version = $"v{description.ApiVersion}",
                  Description = "A sample application with Swagger, Swashbuckle, and API versioning."
  
              };
  
              if (description.IsDeprecated)
              {
                  info.Description += " This API version has been deprecated.";
              }
  
              return info;
          }
      }
  
  
  public static void UseSwaggerMiddleware(this IApplicationBuilder app, IApiVersionDescriptionProvider provider)
          {
              app.UseSwagger();
              // Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.
              app.UseSwaggerUI(c =&gt;
              {
                  // build a swagger endpoint for each discovered API version
                  foreach (var description in provider.ApiVersionDescriptions)
                  {
                      c.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant());
                  }
  
                  //OAuth2
                  c.OAuthClientId("{clientId}");
                  //c.OAuth2RedirectUrl("");
                  //c.OAuthUseBasicAuthenticationWithAccessCodeGrant();
                  c.OAuthClientSecret("{ClientSecret}");
                  c.OAuthAppName("{AppName}");
                  c.OAuthScopeSeparator("openid profile email");
                  c.OAuthAdditionalQueryStringParams(new Dictionary&lt;string, string&gt;
                  {
                      { "response_type","token"}
                  });
  
              });
          }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RVWWv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RVWWv.png" alt="enter image description here"></a></p>
  
  <p>Errors
  Hide</p>
  
  <pre><code>Auth error
  {"state":"VGh1IE9jdCAwMyAyMDE5IDE1OjI4OjEyIEdNVCsxMDAwIChBVVMgRWFzdGVybiBTdGFuZGFyZCBUaW1lKQ==","error":"unsupported_response_type","error_description":"The+response+type+is+not+supported+by+the+authorization+server.+Configured+response+types:+[id_token,+code]."}
  </code></pre>
  
  <p>How do I configure with swagger authorization client with JWT token.</p>