Search in sources :

Example 6 with OAuthToken

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;
}
Also used : OAuthToken(org.eclipse.che.api.auth.shared.dto.OAuthToken)

Example 7 with OAuthToken

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);
}
Also used : OAuthToken(org.eclipse.che.api.auth.shared.dto.OAuthToken) Test(org.testng.annotations.Test)

Example 8 with OAuthToken

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;
}
Also used : OAuthToken(org.eclipse.che.api.auth.shared.dto.OAuthToken) ServerException(org.eclipse.che.api.core.ServerException) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) IOException(java.io.IOException)

Example 9 with 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;
}
Also used : OAuthToken(org.eclipse.che.api.auth.shared.dto.OAuthToken) OAuthCredentialsResponse(com.google.api.client.auth.oauth.OAuthCredentialsResponse)

Aggregations

OAuthToken (org.eclipse.che.api.auth.shared.dto.OAuthToken)9 IOException (java.io.IOException)4 HttpURLConnection (java.net.HttpURLConnection)2 URL (java.net.URL)2 ServerException (org.eclipse.che.api.core.ServerException)2 UnauthorizedException (org.eclipse.che.api.core.UnauthorizedException)2 Test (org.testng.annotations.Test)2 OAuthCredentialsResponse (com.google.api.client.auth.oauth.OAuthCredentialsResponse)1 Credential (com.google.api.client.auth.oauth2.Credential)1 OutputStream (java.io.OutputStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 Link (org.eclipse.che.api.core.rest.shared.dto.Link)1 Subject (org.eclipse.che.commons.subject.Subject)1 GitHubKey (org.eclipse.che.plugin.github.shared.GitHubKey)1