我正在使用带有IdentityServer4包的dotnet core (.NET Core) 3.1。我有一个SPA,希望将其与Identity Server 4集成,因此我正在使用PKCE使用Authorization Code授权类型。我了解此授权类型的基本想法,但不了解如何交换用户名/密码以获取Authorization Code。以下是我的理解。
感谢您能够提供帮助,至少让我朝着正确的方向前进。
- SPA向/authorize端点发出GET请求,例如
http://localhost:5000/connect/authorize?client_id=js&redirect_uri=http://localhost:5003/callback.html&response_type=code&scope=openid profile api1&state=8636d5233f77413584799be6cafe03a7&code_challenge=FbNm1tMkaRMzcSBv4_d5Rpq4VNaqyINVkCAcHsZkKV0&code_challenge_method=S256&response_mode=query
- 这会返回一个302重定向到http://localhost:5000/Account/Login,我假设这应该是由认证服务器托管的登录屏幕。
- 用户提交其凭据,认证服务器验证凭据并返回另一个302重定向到给定的redirect_url,http://localhost:5003/callback.html在这种情况下。重定向网址应包括在查询字符串中生成的Authorization Code和提供的状态。
- SPA验证状态,然后向/token端点发出请求,在标头中包括:授权= Basic Y2xpZW50OnNlY3JldA==,在查询字符串中包括:grant_type = authorization_code,code = Authorization Code ,redirect_uri = http://localhost/redirect
- 认证服务器返回有效令牌。
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryApiResources(Config.GetAllApiResources())
.AddInMemoryClients(Config.GetClients())
.AddTestUsers(Config.GetUsers());
感谢您能够提供帮助,至少让我朝着正确的方向前进。