Azure Active Directory - 在 java 中设置 token 过期

标签 azure active-directory azure-active-directory skype-for-business ucwa

我是 azure 的新手,我正在尝试在 java 中设置我的访问 token 的到期时间,但我无法找到任何示例来设置它。请帮助如何设置到期时间,从 60 分钟到 1 天。

我想将 "expires_in": "3600"增加到至少 8 小时或以上。

在代码中,我无法获得任何方法,例如设置参数或设置 header 。请帮助我,我该怎么做。

这是参数的链接:

https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-configurable-token-lifetimes#cmdlet-reference

谢谢。

AuthenticationContext context = null;
        AuthenticationResult result = null;
        ExecutorService service = null;
        try {

              String refreshToken = request.getParameter("refreshToken");
              String currentUri   = request.getRequestURL().toString();  

            service = Executors.newFixedThreadPool(1);
            context = new AuthenticationContext(authority + tenant + "/", true,
                    service);
            Future<AuthenticationResult> future = context
                    .acquireTokenByRefreshToken(refreshToken,
                            new ClientCredential(clientId, clientSecret), null,
                            null);

            result = future.get();

  //////////////////////////////////////////////////////////
  // token values I'm getting

{
 "access_token": "<requested-access-token>",
 "token_type": "<token-type-value>",
 "expires_in": "3600",

"expires_on": "<access-token-expiration-date-time>",
 "resource": "<app-id-uri>",
 "refresh_token": "<oauth2-refresh-token>",
 "scope": "user_impersonation",

 "id_token": "<unsigned-JSON-web-token>"
}

最佳答案

您将需要使用 Powershell 脚本来创建策略。这是供您引用的脚本。

Install-Module -Name AzureADPreview -Force

Connect-AzureAD -confirm

$policy=New-AzureADPolicy -Definition @('{"TokenLifetimePolicy":{"Version":1,"AccessTokenLifetime":"08:00:00"}}') -DisplayName "tonytestpolicy" -IsOrganizationDefault $false -Type "TokenLifetimePolicy"

如果您必须在java代码中执行此操作,您可以使用graph api。(powershell脚本也调用此api)。这是sample .

POST https://graph.microsoft.com/beta/policies
Content-Type: application/json

{
  "displayName":"CustomTokenLifetimePolicy",
  "definition":["{\"TokenLifetimePolicy\":{\"Version\":1,\"AccessTokenLifetime\":\"8:00:00\"}}"],
  "type":"TokenLifetimePolicy"
}

关于Azure Active Directory - 在 java 中设置 token 过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56957363/

相关文章:

azure - PowerBI 新嵌入功能

c# - 如何知道我的 Windows 用户是域用户?

c# - 在 Azure 中添加、编辑元数据

azure - DocumentDB 是否提供自动索引?

php - 无法通过 GitHub 将 Laravel php 应用程序部署到 azure

C# 和事件目录 : test if an OU exist

php - 验证来自特定组 ldap 事件目录的用户

c# - SqlConnectionStringBuilder 类在 dotnetcore 中缺少 Authentication 属性

azure-active-directory - Microsoft Graph API - 创建应用程序(测试版)

azure - AAD : How do you send an "interactive authorization request" to resolve AADSTS65001 when using MSAL if it's not by calling acquireTokenPopup?