throw new RuntimeException("Client ID is required when configuring an OIDC Provider."); clientId = new ClientID(rawClientId);
ClientID clientId = new ClientID(clientRegistration.getClientId()); Secret clientSecret = new Secret(clientRegistration.getClientSecret()); ClientAuthentication clientAuthentication;
public ClientID getClientId() { return new ClientID(clientId); }
@Override public AuthCodeAndMetadata consumeAuthCode(AuthorizationCode authCode) { String authCodeId = authCode.getValue(); AuthCodeEntity authCodeEntity = entityManager.find(AuthCodeEntity.class, authCodeId); if (authCodeEntity == null) { return null; } AuthCodeAndMetadata authCodeAndMetadata = new AuthCodeAndMetadata( authCodeEntity.getRedirectUri(), authCodeEntity.getUserInfo(), new ClientID(authCodeEntity.getClientId()), authCodeEntity.getLoginSession() != null ? new LoginSessionToken(authCodeEntity.getLoginSession()) : null); entityManager.remove(authCodeEntity); return authCodeAndMetadata; }
/** * Acquires security token from the authority using an device code previously received. * * @param deviceCode The device code result received from calling acquireDeviceCode. * @param callback optional callback object for non-blocking execution. * @return A {@link Future} object representing the {@link AuthenticationResult} of the call. * It contains AccessToken, Refresh Token and the Access Token's expiration time. * @throws AuthenticationException thrown if authorization is pending or another error occurred. * If the errorCode of the exception is AdalErrorCode.AUTHORIZATION_PENDING, * the call needs to be retried until the AccessToken is returned. * DeviceCode.interval - The minimum amount of time in seconds that the client * SHOULD wait between polling requests to the token endpoin */ public Future<AuthenticationResult> acquireTokenByDeviceCode( final DeviceCode deviceCode, final AuthenticationCallback callback) throws AuthenticationException { final ClientAuthentication clientAuth = new ClientAuthenticationPost( ClientAuthenticationMethod.NONE, new ClientID(deviceCode.getClientId())); this.validateDeviceCodeRequestInput(deviceCode, clientAuth, deviceCode.getResource()); final AdalDeviceCodeAuthorizationGrant deviceCodeGrant = new AdalDeviceCodeAuthorizationGrant(deviceCode, deviceCode.getResource()); return this.acquireToken(deviceCodeGrant, clientAuth, callback); }
/** * Acquires security token from the authority using an device code previously received. * * @param deviceCode The device code result received from calling acquireDeviceCode. * @param callback optional callback object for non-blocking execution. * @return A {@link Future} object representing the {@link AuthenticationResult} of the call. * It contains AccessToken, Refresh Token and the Access Token's expiration time. * @throws AuthenticationException thrown if authorization is pending or another error occurred. * If the errorCode of the exception is AdalErrorCode.AUTHORIZATION_PENDING, * the call needs to be retried until the AccessToken is returned. * DeviceCode.interval - The minimum amount of time in seconds that the client * SHOULD wait between polling requests to the token endpoin */ public Future<AuthenticationResult> acquireTokenByDeviceCode( final DeviceCode deviceCode, final AuthenticationCallback callback) throws AuthenticationException { final ClientAuthentication clientAuth = new ClientAuthenticationPost( ClientAuthenticationMethod.NONE, new ClientID(deviceCode.getClientId())); this.validateDeviceCodeRequestInput(deviceCode, clientAuth, deviceCode.getResource()); final AdalDeviceCodeAuthorizationGrant deviceCodeGrant = new AdalDeviceCodeAuthorizationGrant(deviceCode, deviceCode.getResource()); return this.acquireToken(deviceCodeGrant, clientAuth, callback); }
/** * Acquires an access token from the authority on behalf of a user. It * requires using a user token previously received. * * @param resource * Identifier of the target resource that is the recipient of the * requested token. * @param userAssertion * userAssertion to use as Authorization grant * @param credential * The client credential to use for token acquisition. * @param callback * optional callback object for non-blocking execution. * @return A {@link Future} object representing the * {@link AuthenticationResult} of the call. It contains Access * Token and the Access Token's expiration time. Refresh Token * property will be null for this overload. * @throws AuthenticationException {@link AuthenticationException} */ public Future<AuthenticationResult> acquireToken(final String resource, final UserAssertion userAssertion, final ClientCredential credential, final AuthenticationCallback callback) { this.validateOnBehalfOfRequestInput(resource, userAssertion, credential, true); final ClientAuthentication clientAuth = new ClientSecretPost( new ClientID(credential.getClientId()), new Secret( credential.getClientSecret())); return acquireTokenOnBehalfOf(resource, userAssertion, clientAuth, callback); }
/** * Acquires an access token from the authority on behalf of a user. It * requires using a user token previously received. * * @param resource * Identifier of the target resource that is the recipient of the * requested token. * @param userAssertion * userAssertion to use as Authorization grant * @param credential * The client credential to use for token acquisition. * @param callback * optional callback object for non-blocking execution. * @return A {@link Future} object representing the * {@link AuthenticationResult} of the call. It contains Access * Token and the Access Token's expiration time. Refresh Token * property will be null for this overload. * @throws AuthenticationException {@link AuthenticationException} */ public Future<AuthenticationResult> acquireToken(final String resource, final UserAssertion userAssertion, final ClientCredential credential, final AuthenticationCallback callback) { this.validateOnBehalfOfRequestInput(resource, userAssertion, credential, true); final ClientAuthentication clientAuth = new ClientSecretPost( new ClientID(credential.getClientId()), new Secret( credential.getClientSecret())); return acquireTokenOnBehalfOf(resource, userAssertion, clientAuth, callback); }
@Override public AuthCodeAndMetadata consumeAuthCode(AuthorizationCode authCode) { Document document = authCodeCollection.findOneAndDelete(new Document("_id", authCode.getValue())); if (document == null) { return null; } String loginSession = document.getString("loginSession"); return new AuthCodeAndMetadata( document.getString("redirectUri"), new UserInfo(new JSONObject((Map<String, ?>) document.get("userInfo"))), new ClientID(document.getString("clientId")), loginSession != null ? new LoginSessionToken(loginSession) : null); }
ClientAuthenticationMethod.NONE, new ClientID(clientId)); final AdalOAuthAuthorizationGrant authGrant = new AdalOAuthAuthorizationGrant( new RefreshTokenGrant(new RefreshToken(refreshToken)), resource);
/** * Acquires security token from the authority. * * @param resource * Identifier of the target resource that is the recipient of the * requested token. * @param credential * The client credential to use for token acquisition. * @param callback * optional callback object for non-blocking execution. * @return A {@link Future} object representing the * {@link AuthenticationResult} of the call. It contains Access * Token and the Access Token's expiration time. Refresh Token * property will be null for this overload. */ public Future<AuthenticationResult> acquireToken(final String resource, final ClientCredential credential, final AuthenticationCallback callback) { this.validateInput(resource, credential, true); final ClientAuthentication clientAuth = new ClientSecretPost( new ClientID(credential.getClientId()), new Secret( credential.getClientSecret())); final AdalAuthorizatonGrant authGrant = new AdalAuthorizatonGrant( new ClientCredentialsGrant(), resource); return this.acquireToken(authGrant, clientAuth, callback); }
ClientAuthenticationMethod.NONE, new ClientID(clientId));
ClientAuthenticationMethod.NONE, new ClientID(clientId));
/** * Acquires security token from the authority. * * @param resource * Identifier of the target resource that is the recipient of the * requested token. * @param credential * The client credential to use for token acquisition. * @param callback * optional callback object for non-blocking execution. * @return A {@link Future} object representing the * {@link AuthenticationResult} of the call. It contains Access * Token and the Access Token's expiration time. Refresh Token * property will be null for this overload. */ public Future<AuthenticationResult> acquireToken(final String resource, final ClientCredential credential, final AuthenticationCallback callback) { this.validateInput(resource, credential, true); final ClientAuthentication clientAuth = new ClientSecretPost( new ClientID(credential.getClientId()), new Secret( credential.getClientSecret())); final AdalOAuthAuthorizationGrant authGrant = new AdalOAuthAuthorizationGrant( new ClientCredentialsGrant(), resource); return this.acquireToken(authGrant, clientAuth, callback); }
/** * Acquires security token from the authority. * * @param resource * Identifier of the target resource that is the recipient of the * requested token. * @param credential * The client credential to use for token acquisition. * @param callback * optional callback object for non-blocking execution. * @return A {@link Future} object representing the * {@link AuthenticationResult} of the call. It contains Access * Token and the Access Token's expiration time. Refresh Token * property will be null for this overload. */ public Future<AuthenticationResult> acquireToken(final String resource, final ClientCredential credential, final AuthenticationCallback callback) { this.validateInput(resource, credential, true); final ClientAuthentication clientAuth = new ClientSecretPost( new ClientID(credential.getClientId()), new Secret( credential.getClientSecret())); final AdalOAuthAuthorizationGrant authGrant = new AdalOAuthAuthorizationGrant( new ClientCredentialsGrant(), resource); return this.acquireToken(authGrant, clientAuth, callback); }
public static <T extends Token> TokenDocument<T> from(Document document) { String type = document.getString("type"); assert type != null : "type is null"; TokenDocument<T> tokenDocument; UserInfo userInfoObject = new UserInfo(new JSONObject((Map<String,?>)document.get("userInfo"))); ClientID clientIdObj = new ClientID(document.getString("clientId")); LoginSessionToken loginSession = document.getString("sessionId") != null ? new LoginSessionToken(document.getString("sessionId")) : null; Date created = document.getDate("created"); if (TokenType.ACCESS.name().equals(type)) { long tokenLifetime = (document.getDate("expires").getTime() - created.getTime()) / 1000; BearerAccessToken bearerAccessToken = new BearerAccessToken(document.getString("_id"), tokenLifetime, null); tokenDocument = (TokenDocument<T>) new TokenDocument<BearerAccessToken>(bearerAccessToken, created, clientIdObj, loginSession, userInfoObject); } else if (TokenType.REFRESH.name().equals(type)) { int tokenLifetime = 0; if (document.getDate("expires") != null) { tokenLifetime = (int) (document.getDate("expires").getTime() - created.getTime()) / 1000; } RefreshToken refreshToken = new RefreshToken(document.getString("_id")); tokenDocument = (TokenDocument<T>) new TokenDocument<RefreshToken>(refreshToken, created, clientIdObj, loginSession, userInfoObject, tokenLifetime); } else { throw new IllegalArgumentException("unknow token type " + type); } tokenDocument.refreshTokenRef = document.getString("refreshTokenRef"); return tokenDocument; }
final ClientID _clientID = new ClientID(configuration.getClientId()); final Secret _secret = new Secret(configuration.getSecret());
new ClientID(credential.getClientId()), new Secret( credential.getClientSecret())); final AdalAuthorizatonGrant authGrant = new AdalAuthorizatonGrant(
new ClientID(credential.getClientId()), new Secret( credential.getClientSecret())); final AdalOAuthAuthorizationGrant authGrant = new AdalOAuthAuthorizationGrant(
new ClientID(credential.getClientId()), new Secret( credential.getClientSecret())); final AdalOAuthAuthorizationGrant authGrant = new AdalOAuthAuthorizationGrant(