use of io.jans.as.model.uma.wrapper.Token in project jans by JanssenProject.
the class UmaClient method request.
@SuppressWarnings("java:S1874")
public static Token request(final String tokenUrl, final String umaClientId, final String umaClientSecret, UmaScopeType scopeType, ClientHttpEngine engine, String... scopeArray) {
StringBuilder scope = new StringBuilder(scopeType.getValue());
if (scopeArray != null && scopeArray.length > 0) {
for (String s : scopeArray) {
scope.append(" ").append(s);
}
}
TokenClient tokenClient = new TokenClient(tokenUrl);
if (engine != null) {
tokenClient.setExecutor(engine);
}
TokenResponse response = tokenClient.execClientCredentialsGrant(scope.toString(), umaClientId, umaClientSecret);
if (response.getStatus() == 200) {
final String patToken = response.getAccessToken();
final Integer expiresIn = response.getExpiresIn();
if (Util.allNotBlank(patToken)) {
return new Token(null, null, patToken, scopeType.getValue(), expiresIn);
}
}
return null;
}
use of io.jans.as.model.uma.wrapper.Token in project jans by JanssenProject.
the class UmaClient method request.
public static Token request(final String tokenUrl, final TokenRequest tokenRequest) {
if (tokenRequest.getGrantType() != GrantType.CLIENT_CREDENTIALS) {
return null;
}
TokenClient tokenClient = new TokenClient(tokenUrl);
tokenClient.setRequest(tokenRequest);
TokenResponse response = tokenClient.exec();
if (response.getStatus() == 200) {
final String patToken = response.getAccessToken();
final Integer expiresIn = response.getExpiresIn();
if (Util.allNotBlank(patToken)) {
return new Token(null, null, patToken, response.getScope(), expiresIn);
}
}
return null;
}
use of io.jans.as.model.uma.wrapper.Token in project jans by JanssenProject.
the class IntrospectionWsHttpTest method introspectWithValidAuthorizationButInvalidTokenShouldReturnActiveFalse.
@Test
@Parameters({ "umaPatClientId", "umaPatClientSecret" })
public void introspectWithValidAuthorizationButInvalidTokenShouldReturnActiveFalse(final String umaPatClientId, final String umaPatClientSecret) throws Exception {
final Token authorization = UmaClient.requestPat(tokenEndpoint, umaPatClientId, umaPatClientSecret, clientEngine(true));
final IntrospectionService introspectionService = ClientFactory.instance().createIntrospectionService(introspectionEndpoint, clientEngine(true));
final IntrospectionResponse introspectionResponse = introspectionService.introspectToken("Bearer " + authorization.getAccessToken(), "invalid_token");
assertNotNull(introspectionResponse);
assertFalse(introspectionResponse.isActive());
}
use of io.jans.as.model.uma.wrapper.Token in project jans by JanssenProject.
the class AuthUtil method requestAccessToken.
public Token requestAccessToken(final String tokenUrl, final String clientId, final List<String> scopes) {
log.debug("Access Token Request - tokenUrl:{}, clientId:{}, scopes:{}", tokenUrl, clientId, scopes);
// Get clientSecret
String clientSecret = this.getClientDecryptPassword(clientId);
// distinct scopes
Set<String> scopesSet = new HashSet<>(scopes);
StringBuilder scope = new StringBuilder(ScopeType.OPENID.getValue());
for (String s : scopesSet) {
scope.append(" ").append(s);
}
log.debug("Scope required - {}", scope);
TokenResponse tokenResponse = AuthClientFactory.requestAccessToken(tokenUrl, clientId, clientSecret, scope.toString());
if (tokenResponse != null) {
log.debug("Token Response - tokenScope: {}, tokenAccessToken: {} ", tokenResponse.getScope(), tokenResponse.getAccessToken());
final String accessToken = tokenResponse.getAccessToken();
final Integer expiresIn = tokenResponse.getExpiresIn();
if (Util.allNotBlank(accessToken)) {
return new Token(null, null, accessToken, ScopeType.OPENID.getValue(), expiresIn);
}
}
return null;
}
use of io.jans.as.model.uma.wrapper.Token in project jans by JanssenProject.
the class ObtainPatProvider method requestPat.
public Token requestPat(final String tokenUrl, final String umaClientId, final String umaClientSecret, String... scopeArray) throws Exception {
String scope = UmaScopeType.PROTECTION.getValue();
if (scopeArray != null && scopeArray.length > 0) {
for (String s : scopeArray) {
scope = scope + " " + s;
}
}
TokenClient tokenClient = new TokenClient(tokenUrl);
tokenClient.setExecutor(serviceProvider.getClientEngine());
TokenResponse response = tokenClient.execClientCredentialsGrant(scope, umaClientId, umaClientSecret);
if (response.getStatus() == 200) {
final String patToken = response.getAccessToken();
final Integer expiresIn = response.getExpiresIn();
if (Util.allNotBlank(patToken)) {
return new Token(null, null, patToken, UmaScopeType.PROTECTION.getValue(), expiresIn);
}
}
return null;
}
Aggregations