【问题标题】:Microsoft Graph API OrganizationFromTenantGuidNotFound using MSAL使用 MSAL 的 Microsoft Graph API OrganizationFromTenantGuidNotFound
【发布时间】:2019-05-03 03:17:41
【问题描述】:

在 AAD 应用注册中,隐式授权流为 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"
         }
     }
}

【问题讨论】:

标签: microsoft-graph-api single-page-application msal


【解决方案1】:

我遇到了同样的问题,经过 4 小时的反复试验,我解决了这个问题。

我的情况有点不同,但可能适用于你的情况。

我试图阅读用户电子邮件 (/users/userId/messages),但由于同样的错误而失败。尝试获取用户信息确实有效,但尝试获取消息失败,这让我意识到即使用户确实存在于我的 AD 中,但交换帐户的实际 AD 是不同的......一旦我移动了我的应用注册到正确的 AD 一切正常...

希望对您有所帮助...

【讨论】:

【解决方案2】:

我在使用 Azure AD 中的tenantId 时遇到了同样的错误。

我在“consumers”(“common”、“organizations”)上更改了tenantId 后修复了它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 2019-01-10
    • 2020-07-28
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    相关资源
    最近更新 更多