加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

microsoft-graph – 使用MSAL的Microsoft Graph API Organizatio

发布时间:2020-12-14 05:34:39 所属栏目:Windows 来源:网络整理
导读:在AAD应用程序注册中,Implicit Grant Flow为true; 我们已将权限委派给User.Read和User.Read.All. private static getContext(): Msal.UserAgentApplication { if (AuthenticationService.Context) return AuthenticationService.Context; const logger = new
在AAD应用程序注册中,Implicit Grant Flow为true;
我们已将权限委派给User.Read和User.Read.All.

private static getContext(): Msal.UserAgentApplication {
    if (AuthenticationService.Context) return AuthenticationService.Context;
    const logger = new Msal.Logger((_logLevel,message,_piiEnabled) => {
        console.log(message);
    },{ level: Msal.LogLevel.Verbose,correlationId: "12345" });

    AuthenticationService.Context = new Msal.UserAgentApplication(
        Environment().authentication.clientId,AuthenticationService.getAuthority(),(errorDesc,token,error,_tokenType) => {
            if (token) {
                AuthenticationService.isAuthenticated = true;
                AuthenticationService.accessToken = token;
            } else {
                const localizedError: string = LocalizationService.localize(error);
                alert(localizedError !== error ? localizedError : errorDesc);
            }
        },{
            logger: logger,storeAuthStateInCookie: true,state: "12345",cacheLocation: "localStorage" // enable this for IE,as sessionStorage does not work for localhost.
        });
    if (AuthenticationService.Context.getUser()) {
        AuthenticationService.isAuthenticated = true;
    }

    return AuthenticationService.Context;
}

我们有登录方法:

public static login(): void {
    const context: Msal.UserAgentApplication = AuthenticationService.getContext();
    if (context.loginInProgress()) return;
    AuthenticationService.CurrentUser = null;
    context.loginRedirect(AuthenticationService.SCOPES);
}

我们有获取图表令牌的方法:

public static async getGraphToken(): Promise<string | null> {
    const authContext: Msal.UserAgentApplication = AuthenticationService.getContext();
    const cachedUser: Msal.User = authContext.getUser();
    if (!cachedUser) {
        return null;
    }
    return authContext.acquireTokenSilent(AuthenticationService.SCOPES);
}

当我使用图形令牌获取用户照片时,我有:

{
    "error": {
        "code": "OrganizationFromTenantGuidNotFound","message": "The tenant for tenant guid '68cc0dcb-5873-4ea0-a498-fe57e9b51827' does not exist.","innerError": {
            "request-id": "b402e405-342a-4002-a880-84f30413cbf7","date": "2018-11-30T23:39:23"
         }
     }
}

解决方法

我遇到了同样的问题,经过4个小时的试错,我解决了这个问题.

我的情况有点不同,但它可能适用于您的情况.

我试图读取失败并出现相同错误的用户电子邮件(/ users / userId / messages).试图获取用户的信息确实有效,但试图让消息失败,这让我意识到即使用户确实存在于我的AD上,交换帐户的实际AD也不同……一旦我移动了我的应用注册正确的AD一切都很完美……

希望有帮助……

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读