use of org.eclipse.che.api.auth.shared.dto.OAuthToken in project che by eclipse.
the class OAuthAuthenticatorTokenProvider method getToken.
@Override
public OAuthToken getToken(String oauthProviderName, String userId) throws IOException {
OAuthAuthenticator oAuthAuthenticator = oAuthAuthenticatorProvider.getAuthenticator(oauthProviderName);
OAuthToken token;
if (oAuthAuthenticator != null && (token = oAuthAuthenticator.getToken(userId)) != null) {
return token;
}
return null;
}
use of org.eclipse.che.api.auth.shared.dto.OAuthToken in project che by eclipse.
the class RemoteOAuthTokenProviderTest method shouldReturnToken.
@Test
public void shouldReturnToken() throws Exception {
//given
OAuthToken expected = DtoFactory.newDto(OAuthToken.class).withScope("scope").withToken("token");
when(httpJsonResponse.asDto(any(Class.class))).thenReturn(expected);
when(httpJsonRequest.request()).thenReturn(httpJsonResponse);
//when
OAuthToken actual = tokenProvider.getToken("google", "id");
//then
assertEquals(actual, expected);
}
use of org.eclipse.che.api.auth.shared.dto.OAuthToken in project che by eclipse.
the class GitHubFactory method getToken.
private String getToken() throws ServerException, UnauthorizedException {
OAuthToken token;
try {
token = oauthTokenProvider.getToken("github", EnvironmentContext.getCurrent().getSubject().getUserId());
} catch (IOException e) {
throw new ServerException(e.getMessage());
}
String oauthToken = token != null ? token.getToken() : null;
if (oauthToken == null || oauthToken.isEmpty()) {
throw new UnauthorizedException("User doesn't have access token to github");
}
return oauthToken;
}
use of org.eclipse.che.api.auth.shared.dto.OAuthToken in project che by eclipse.
the class OAuthAuthenticator method computeAuthorizationHeader.
/**
* Compute the Authorization header to sign the OAuth 1 request.
*
* @param userId
* the user id.
* @param requestMethod
* the HTTP request method.
* @param requestUrl
* the HTTP request url with encoded query parameters.
* @return the authorization header value, or {@code null} if token was not found for given user id.
* @throws OAuthAuthenticationException
* if authentication failed.
*/
String computeAuthorizationHeader(final String userId, final String requestMethod, final String requestUrl) throws OAuthAuthenticationException {
final OAuthCredentialsResponse credentials = new OAuthCredentialsResponse();
OAuthToken oauthToken = getToken(userId);
credentials.token = oauthToken != null ? oauthToken.getToken() : null;
if (credentials.token != null) {
return computeAuthorizationHeader(requestMethod, requestUrl, credentials.token, credentials.tokenSecret);
}
return null;
}
Aggregations