总结一句话,其实很简单
在什么Clients 拿的认证权限Scope 就去 去开什么Scope限制的服务接口门
在写Clients的时候,会有Scope,看下面的代码
new Client { ClientName = "手机APP", ClientId = "lym.password", Enabled = true, AccessTokenType = AccessTokenType.Reference, Flow = Flows.ResourceOwner, ClientSecrets = new List<Secret> { new Secret("21B5F798-BE55-42BC-8AA8-0025B903DC3B".Sha256(),"WebAPI客户端") }, AllowedScopes = new List<string> { Constants.StandardScopes.OpenId, Constants.StandardScopes.Profile, Constants.StandardScopes.OfflineAccess, "cloudservices" } },
这里是 密码模式,通过这个客户端拿到具有
cloudservices Scope的钥匙,那么我们就去开门
这里我有设置了一个WebAPI
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions { Authority = LYM.Unity.AppSetting.AppSettingsHelper.GetString("Authority"), ValidationMode = ValidationMode.ValidationEndpoint, RequiredScopes = new[] { //"openid", //"profile", //"offline_access", "cloudservices" } });
这个就是相当于门上的锁,我设置了需要什么样的钥匙来开
其次是所谓的客户端模式 也是一样的道理~~~