我有一个网络应用程序(Angular 7)使用
MSAL Angular
here
:
-
user_impersonation
对于Web API(委派)
-
User.Read; Mail.Send
对于MS Graph(委派)
现在我想用ADAL for.NET从webapi调用microsoftwraph来获取一些数据
on behalf of a user
.
跟随
this instructions
我应该配置
consentScopes
和
protectedResourceMap
但是,由于我使用AAD v1,因此不能在增量同意的情况下使用作用域。
我
found
代表
Web API与MS Graph的通信流程。
更新
以下是从Web API发出访问令牌请求的代码:
string accessToken = null;
var userAssertion = new UserAssertion(
<userAccessToken>,
"urn:ietf:params:oauth:grant-type:jwt-bearer",
userName);
var authority = "https://login.microsoftonline.com/" + <tenant> + "/";
var clientCredencial = new ClientCredential(<clientId>, <clientSecret>);
var authContext = new AuthenticationContext(authority, null);
try
{
var authResult = await authContext.AcquireTokenAsync(
"https://graph.microsoft.com",
clientCredencial,
userAssertion);
accessToken = authResult.AccessToken;
}
catch (AdalServiceException ex) { throw; }
知识应用程序
在Web API清单中:
"knownClientApplications": [
"<WebAppAppId>"
],
以下是Web应用程序(MsalModule)中设置的范围:
consentScopes:
[
'https://webapi.example.com/user_impersonation'
],
在这种情况下,Web应用程序需要在同意屏幕上具有以下权限:
如果我试图获取MS Graph的访问令牌,则会出现错误:
{“AADSTS65001:用户或管理员未同意使用ID为“webapicentid”且名为“WebApiAppName”的应用程序。为此用户和资源发送交互式授权请求。}