一步一步學習IdentityServer4 (5) .NETCore2.0 Swagger


首先添加nuget: Swashbuckle.AspNetCore

 services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version = "v1",
                    Title = "IdentityServer4 & WebApi"
                });
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath = Path.Combine(basePath, "LYM.ApiServices.xml");
                c.IncludeXmlComments(xmlPath);
            }
             );
 app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(c => {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "IdentityServer4 & WebApi");
            });

 

沒有問題,值得注意的是webapi寫法與mvc有區別

自定義名稱需要這樣寫

/// <summary>
        /// ClientTest測試
        /// </summary>
        /// <param name="value"></param>
        [HttpPost("ClientTest")]
        public void ClientTest([FromBody]string value)
        {

        }

 名稱已經放到上面去了,而在傳統的寫法[RoutePrefix("api/Client")] 被取代了,

如果需要Identityserver4授權需要添加下面的處理 與IdentityServer3一樣

  c.AddSecurityDefinition("oauth2", new OAuth2Scheme
                {
                    Type = "oauth2",
                    Flow = "implicit",
                    AuthorizationUrl = "http://Identityserver4授權地址",
                    Scopes = new Dictionary<string, string>
                    {
                        { "cloudservices", "cloudservices" },
                        { "clientservices", "clientservices" }
                    }
                });
          
                c.OperationFilter<SecurityRequirementsOperationFilter>();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM