我一直在努力将旧的 Web 表单应用程序转换为使用 Azure AD 身份验证,一切正常,但我注意到,虽然我在应用程序注册中添加了客户端密钥,但我的 Web 应用程序无需传递客户端密钥即可进行身份验证。
这是正常行为吗?我可能在这里遗漏了一些简单的东西,但我的印象是创建客户端密钥意味着对此应用程序注册表的身份验证请求必须包含客户端密钥,否则 Azure AD 会假设该请求来自未经授权的应用程序。
在我的 StartupAuth 中,我只是省略了客户端密钥(故意用于测试目的)
app.UseOpenIdConnectAuthentication(New OpenIdConnectAuthenticationOptions() With {
.ClientId = clientId,
.Authority = authority,
.RedirectUri = redirectUri,
.PostLogoutRedirectUri = postLogoutRedirectUri,
.Notifications = New OpenIdConnectAuthenticationNotifications() With {
.AuthenticationFailed = Function(context) System.Threading.Tasks.Task.FromResult(0),
.SecurityTokenValidated = Function(context)
Return OnSecurityTokenValidated(context)
End Function
}}
)
我无需提供客户端密钥即可获取 ID 令牌,但我希望它会拒绝该请求。
注意:机密 Web 应用程序需要客户端密钥。如果您的应用程序配置为公共客户端,则无需传递客户端密钥。
如果
Allow public client flows
启用为yes,那么该应用程序是公共客户端,您将能够在没有客户端密钥的情况下使用应用程序注册。
对于 sample,我生成了访问令牌而不传递客户端密钥:
https://login.microsoftonline.com/tenantId/oauth2/token
client_id : xxxxxx-xxx-xxx-xxxx-xxxxxxxx
grant_type : password
scope : https://graph.microsoft.com/user.read
username : user@********.onmicrosoft.com
password : ******
如果您想使用客户端密钥,请将
Allow public client flows
启用为NO。
参考:
无需客户端密钥的委托访问令牌 - Microsoft 问答 CarlZhao-MSFT