我正在使用OWIN OpenID Connect Middleware连接到Azure AD。我能够成功验证用户并重定向回回调端点。我在这里有点困惑,因为我只收到id_token
&回复中code
。
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
AuthenticationType = "Azure AD - TEST",
Caption = "azure AD",
SignInAsAuthenticationType = signInAsType,
ClientId = "some guid",
Authority = "https://sts.windows.net/idp",
ResponseType = OpenIdConnectResponseTypes.CodeIdToken,
RedirectUri = "https://localhost:44392/ExternalLogins/Callback/",
AuthenticationMode = AuthenticationMode.Active,
});
回调方法:
[HttpPost]
[Route("ExternalLogins/Callback")]
[AllowAnonymous]
public async Task<IHttpActionResult> ExternalLoginCallback()
{
var content = await Request.Content.ReadAsStringAsync();
// I could see the content is a string with id_token, code , state etc.
//id_token is a JWT, so i can decode it and see the user claims and use them later
}
我的问题是:
access_token
?code
交换access_token
,但不确定我需要调用哪个Azure端点才能获得access_token
?AuthenticationMode.Active
和AuthenticationMode.Passive
之间的区别是什么?答案 0 :(得分:0)
access token
拨打电话给api。假设您想要在MS Graph上调用/ get端点,您将access token
填入http请求的正文中,并在其前面加上关键字Bearer ey...
。
此外,您还需要进入Azure门户并配置要访问的委派权限。 我只想补充一点,如果您想使用Azure AD查看一些示例代码,可以转到Azure AD Dev Guide或Azure AD code samples on Github。