设为首页 加入收藏

TOP

微服务(入门四):identityServer的简单使用(客户端授权+密码授权)(四)
2019-09-17 18:44:25 】 浏览:57
Tags:服务 入门 identityServer 简单 使用 客户端 授权 密码
AllowedScopes = { "api1" } } , new Client { ClientId = "client1", AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, // 用于认证的密码 ClientSecrets = { new Secret("laozheng".Sha256()) }, RequireClientSecret=false, // 客户端有权访问的范围(Scopes) AllowedScopes = { "api1" } } }; } public static List<TestUser> GetTestUsers() { return new List<TestUser> { new TestUser{ SubjectId="1", Password="111", Username="111", } }; } } }

1.1 修改startup.cs文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.Models;
using IdentityServer4.Test;
using IdentityServer4Test.IndntityConfig;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace IdentityServer4Test
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            // 在DI容器中注入identityServer服务
            services.AddIdentityServer()
         
        .AddInMemoryApiResources(IdentityServerConfig.GetResources())
        .AddInMemoryClients(IdentityServerConfig.GetClients())
        .AddTestUsers(IdentityServerConfig.GetTestUsers())
            .AddDeveloperSigningCredential();
            

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //添加identityserver中间件到http管道
            app.UseIdentityServer();
            //app.UseMvc();
        }
    }
}

 

2.获取token

 

 

3.通过刚才获取到的token访问接口

 

 

 

 

 

快速入口:微服务(入门一):netcore安装部署consul

快速入口: 微服务(入门二):netcore通过consul注册服务

快速入口: 微服务(入门三):netcore ocelot api网关结合consul服务发现

快速入口:微服务(入门四):identityServer的简单使用(客户端授权) 

首页 上一页 1 2 3 4 下一页 尾页 4/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇第15章 使用EntityFramework Core.. 下一篇第4章 打包和构建 - Identity Ser..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目