大家好,如果我要朝正确的方向走,我需要一些指导。 我的Identity Server客户端具有以下设置:
new Client
{
ClientId = "XamarinAndAngularClient",
ClientName = "Xamarin and Angular client(Code with PKCE)",
RedirectUris = new List<string>
{
"http://localhost:4200",
"http://localhost:4200/auth-callback"
},
PostLogoutRedirectUris =
{
"http://localhost:4200",
"https://localhost:4200",
},
RequireClientSecret = false,
AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Address,
"myprotectedeapi"
},
AllowOfflineAccess = true,
RefreshTokenUsage = TokenUsage.ReUse
}
Angular SPA将此客户端与oidc-client-js一起使用,效果很好。我已经添加了Xamarin应用程序,以使用具有以下设置的同一客户端:
var options = new OidcClientOptions
{
Authority = "https://myidentityserver.com/",
ClientId = "XamarinAndAngularClient",
Scope = "openid profile address myprotectedeapi",
//RedirectUri = "xamarinformsclients://callback",
RedirectUri = "http://localhost:4200/auth-callback",
Browser = browser,
FilterClaims = false,
Flow = OidcClientOptions.AuthenticationFlow.AuthorizationCode,
ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect,
};
Xamarin表单设置的想法是将用户重定向到Indentity服务器登录屏幕,以及当他提供了所需凭据以重定向到Angular SPA时。当前,每次oidc-client-js返回错误时都会发生这种重定向到Angular的情况:在存储中找不到匹配状态。我的问题是:我当前的想法/方法是否正确,如果没有,我该怎么做才能“通知” oidc-client-js Xamarin回调中的代码(包含身份服务器生成的状态和会话状态)可以使用吗?
答案 0 :(得分:1)
正如库告诉您的那样,这里的问题是,向authorize
端点发出第一个请求的应用程序确实必须与获取auth回调的应用程序相同,并且与导致后续请求的应用程序相同。请求到token
端点。
代码+ PKCE 流不需要使用客户端机密,因为它保证了第一个请求授权的客户端,第二个对令牌进行授权的客户端(这就是PKCE所做的) )。这里唯一的秘密不是秘密,它是您的redirect_uri
,因此只有坐在该uri上的应用程序才能完成流程。这样,我们无需任何秘密即可对client
(您的有角度的SPA)进行身份验证。
话虽如此,您可以在Xamarin.Forms上做的是在SPA上调用一个终结点,从那里启动整个流程,这在维护方面也更加方便,因为您只有将oidc配置保留在应用程序的一侧(角度spa)。
上对此流进行了详细解释。