Java Code Examples for com.microsoft.aad.adal4j.AuthenticationResult#isMultipleResourceRefreshToken()
The following examples show how to use
com.microsoft.aad.adal4j.AuthenticationResult#isMultipleResourceRefreshToken() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserTokenCredentials.java From autorest-clientruntime-for-java with MIT License | 6 votes |
@Override public synchronized String getToken(String resource) throws IOException { // Find exact match for the resource AuthenticationResult authenticationResult = tokens.get(resource); // Return if found and not expired if (authenticationResult != null && authenticationResult.getExpiresOnDate().after(new Date())) { return authenticationResult.getAccessToken(); } // If found then refresh boolean shouldRefresh = authenticationResult != null; // If not found for the resource, but is MRRT then also refresh if (authenticationResult == null && !tokens.isEmpty()) { authenticationResult = new ArrayList<>(tokens.values()).get(0); shouldRefresh = authenticationResult.isMultipleResourceRefreshToken(); } // Refresh if (shouldRefresh) { authenticationResult = acquireAccessTokenFromRefreshToken(resource, authenticationResult.getRefreshToken()); } // If refresh fails or not refreshable, acquire new token if (authenticationResult == null) { authenticationResult = acquireNewAccessToken(resource); } tokens.put(resource, authenticationResult); return authenticationResult.getAccessToken(); }
Example 2
Source File: DelegatedTokenCredentials.java From autorest-clientruntime-for-java with MIT License | 6 votes |
@Override public synchronized String getToken(String resource) throws IOException { // Find exact match for the resource AuthenticationResult authenticationResult = tokens.get(resource); // Return if found and not expired if (authenticationResult != null && authenticationResult.getExpiresOnDate().after(new Date())) { return authenticationResult.getAccessToken(); } // If found then refresh boolean shouldRefresh = authenticationResult != null; // If not found for the resource, but is MRRT then also refresh if (authenticationResult == null && !tokens.isEmpty()) { authenticationResult = new ArrayList<>(tokens.values()).get(0); shouldRefresh = authenticationResult.isMultipleResourceRefreshToken(); } // Refresh if (shouldRefresh) { authenticationResult = acquireAccessTokenFromRefreshToken(resource, authenticationResult.getRefreshToken()); } // If refresh fails or not refreshable, acquire new token if (authenticationResult == null) { authenticationResult = acquireNewAccessToken(resource); } tokens.put(resource, authenticationResult); return authenticationResult.getAccessToken(); }
Example 3
Source File: CbDelegatedTokenCredentials.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public synchronized String getToken(String resource) throws IOException { // Find exact match for the resource AuthenticationResult authenticationResult = tokens.get(resource); // Return if found and not expired if (authenticationResult != null && authenticationResult.getExpiresOnDate().after(new Date())) { return authenticationResult.getAccessToken(); } // If found then refresh boolean shouldRefresh = authenticationResult != null; // If not found for the resource, but is MRRT then also refresh if (authenticationResult == null && !tokens.isEmpty()) { authenticationResult = new ArrayList<>(tokens.values()).get(0); shouldRefresh = authenticationResult.isMultipleResourceRefreshToken(); } // Refresh if (shouldRefresh) { boolean multipleResourceRefreshToken = authenticationResult.isMultipleResourceRefreshToken(); String refreshToken = authenticationResult.getRefreshToken(); authenticationResult = acquireAccessTokenFromRefreshToken(resource, refreshToken, multipleResourceRefreshToken); } // If refresh fails or not refreshable, acquire new token if (authenticationResult == null) { authenticationResult = acquireNewAccessToken(resource); } tokens.put(resource, authenticationResult); return authenticationResult.getAccessToken(); }