gpt4 book ai didi

java - 要登录此应用程序,必须将帐户添加到 目录

转载 作者:行者123 更新时间:2023-11-30 05:58:54 25 4
gpt4 key购买 nike

我正在尝试进行身份验证和应用程序并获取不记名 token 以供进一步使用。我收到错误,这是该线程的标题。

另一个线程描述了同样的事情,只是我的代码是用 Java 编写的。解决方法是使用证书方法。 "To sign into this application the account must be added to the domain.com directory"

有人可以描述此解决方法的详细步骤吗:- 证书方法或者我如何用任何其他方法修复以下代码或者有任何其他方法来完成整个任务

这是我的代码

private final static String AUTHORITY = "https://login.microsoftonline.com/<tenantId>/OAuth2/Authorize";
private final static String CLIENT_ID = "<Client_Id>";
private final static String CLIENT_SECRET = "<Secret>";

public static void main(String args[]) throws Exception {

try (BufferedReader br = new BufferedReader(new InputStreamReader(
System.in))) {

String username = CLIENT_ID;
String password = CLIENT_SECRET;

service = Executors.newFixedThreadPool(1);

context = new AuthenticationContext(AUTHORITY, false, service);
Future<AuthenticationResult> future = context.acquireToken(
"https://graph.microsoft.com", CLIENT_ID, username, password,
null);
result = future.get();

}
finally {
service.shutdown();
}

}

我已在 AAD 应用程序注册中注册了我的应用程序。 Client_Id是App Id,Secret是上面代码中的一个key

最佳答案

如果您想让代码以当前形式运行而不需要任何解决方法,请检查以下内容 -

  1. 确保您在第一行代码中指定了正确的tenantId GUID

    获取tenantid的步骤 -

    登录到 Azure 门户,导航到 Azure AD,转到属性(如下面的屏幕截图所示),目录 ID 将为您提供 GUID。

enter image description here

 private final static String AUTHORITY = "https://login.microsoftonline.com/<tenantId>/OAuth2/Authorize";
  • 确保您使用的用户名属于您的 AzureAD 租户。

    一个可能的原因可能是您使用的是 Microsoft 帐户,如 [email protected]或 hotmail.com 等。尝试使用在此 Azure AD 中创建的帐户,例如 [email protected]或您的租户使用的任何其他经过验证的域。

  • Future<AuthenticationResult> future = context.acquireToken("https://graph.microsoft.com", CLIENT_ID, username, password, null);

    关于java - 要登录此应用程序,必须将帐户添加到 <TenantID> 目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52618487/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com