Search in sources :

Example 1 with WebDriverHelper

use of org.orcid.api.common.WebDriverHelper in project ORCID-Source by ORCID.

the class RefreshTokenTest method generateRefreshTokenInMemberAPITest.

@Test
public void generateRefreshTokenInMemberAPITest() throws InterruptedException, JSONException {
    String clientId = getClient1ClientId();
    String clientSecret = getClient1ClientSecret();
    String redirectUri = getClient1RedirectUri();
    String userId = getUser1OrcidId();
    String userPassword = getUser1Password();
    WebDriverHelper webDriverHelper = new WebDriverHelper(webDriver, this.getWebBaseUrl(), redirectUri);
    oauthHelper.setWebDriverHelper(webDriverHelper);
    String authorizationCode = oauthHelper.getAuthorizationCode(clientId, ScopePathType.ACTIVITIES_UPDATE.value(), userId, userPassword, true);
    assertNotNull(authorizationCode);
    assertFalse(PojoUtil.isEmpty(authorizationCode));
    ClientResponse tokenResponse = oauthHelper.getClientResponse(clientId, clientSecret, null, redirectUri, authorizationCode);
    assertEquals(200, tokenResponse.getStatus());
    String body = tokenResponse.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    String accessToken = (String) jsonObject.get("access_token");
    assertNotNull(accessToken);
    String refreshToken = (String) jsonObject.get("refresh_token");
    assertNotNull(refreshToken);
    MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.add("client_id", clientId);
    params.add("client_secret", clientSecret);
    params.add("redirect_uri", redirectUri);
    params.add("refresh_token", refreshToken);
    params.add("grant_type", "refresh_token");
    tokenResponse = oauthHelper.getOauthT2Client().obtainOauth2RefreshTokenPost("refresh_token", accessToken, params);
    assertNotNull(tokenResponse);
    assertEquals(200, tokenResponse.getStatus());
    body = tokenResponse.getEntity(String.class);
    jsonObject = new JSONObject(body);
    String refreshedAccessToken = (String) jsonObject.get("access_token");
    assertNotNull(refreshedAccessToken);
    String refreshedRefreshToken = (String) jsonObject.get("refresh_token");
    assertNotNull(refreshedRefreshToken);
    assertFalse(refreshedAccessToken.equals(accessToken));
    assertFalse(refreshedRefreshToken.equals(refreshToken));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebDriverHelper(org.orcid.api.common.WebDriverHelper) JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 2 with WebDriverHelper

use of org.orcid.api.common.WebDriverHelper in project ORCID-Source by ORCID.

the class BlackBoxBase method getAccessToken.

public String getAccessToken(String userName, String userPassword, List<String> scopes, String clientId, String clientSecret, String clientRedirectUri, boolean longLife) throws InterruptedException, JSONException {
    Collections.sort(scopes);
    String scopesString = StringUtils.join(scopes, " ");
    String accessTokenKey = clientId + ":" + userName + ":" + scopesString;
    if (accessTokens.containsKey(accessTokenKey)) {
        return accessTokens.get(accessTokenKey);
    }
    WebDriverHelper webDriverHelper = new WebDriverHelper(getWebDriver(), getWebBaseUrl(), clientRedirectUri);
    oauthHelper.setWebDriverHelper(webDriverHelper);
    String token = oauthHelper.obtainAccessToken(clientId, clientSecret, scopesString, userName, userPassword, clientRedirectUri, longLife);
    accessTokens.put(accessTokenKey, token);
    return token;
}
Also used : WebDriverHelper(org.orcid.api.common.WebDriverHelper)

Example 3 with WebDriverHelper

use of org.orcid.api.common.WebDriverHelper in project ORCID-Source by ORCID.

the class BlackBoxBase method getNonCachedAccessTokens.

public String getNonCachedAccessTokens(String userName, String userPassword, List<String> scopes, String clientId, String clientSecret, String clientRedirectUri) throws JSONException, InterruptedException {
    String scopesString = StringUtils.join(scopes, " ");
    WebDriverHelper webDriverHelper = new WebDriverHelper(getWebDriver(), getWebBaseUrl(), clientRedirectUri);
    oauthHelper.setWebDriverHelper(webDriverHelper);
    return oauthHelper.obtainAccessToken(clientId, clientSecret, scopesString, userName, userPassword, clientRedirectUri);
}
Also used : WebDriverHelper(org.orcid.api.common.WebDriverHelper)

Example 4 with WebDriverHelper

use of org.orcid.api.common.WebDriverHelper in project ORCID-Source by ORCID.

the class BlackBoxBase method getAccessToken.

public String getAccessToken(String userName, String userPassword, List<String> scopes, String clientId, String clientSecret, String clientRedirectUri) throws InterruptedException, JSONException {
    Collections.sort(scopes);
    String scopesString = StringUtils.join(scopes, " ");
    String accessTokenKey = clientId + ":" + userName + ":" + scopesString;
    if (accessTokens.containsKey(accessTokenKey)) {
        return accessTokens.get(accessTokenKey);
    }
    WebDriverHelper webDriverHelper = new WebDriverHelper(getWebDriver(), getWebBaseUrl(), clientRedirectUri);
    oauthHelper.setWebDriverHelper(webDriverHelper);
    String token = oauthHelper.obtainAccessToken(clientId, clientSecret, scopesString, userName, userPassword, clientRedirectUri);
    accessTokens.put(accessTokenKey, token);
    return token;
}
Also used : WebDriverHelper(org.orcid.api.common.WebDriverHelper)

Example 5 with WebDriverHelper

use of org.orcid.api.common.WebDriverHelper in project ORCID-Source by ORCID.

the class BlackBoxBase method getAuthorizationCode.

public String getAuthorizationCode(String clientId, String clientRedirectUri, String scopes, String userId, String password, boolean longLife, Map<String, String> params) throws InterruptedException {
    WebDriverHelper webDriverHelper = new WebDriverHelper(getWebDriver(), getWebBaseUrl(), clientRedirectUri);
    oauthHelper.setWebDriverHelper(webDriverHelper);
    return oauthHelper.getAuthorizationCode(clientId, scopes, userId, password, longLife, params);
}
Also used : WebDriverHelper(org.orcid.api.common.WebDriverHelper)

Aggregations

WebDriverHelper (org.orcid.api.common.WebDriverHelper)7 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Test (org.junit.Test)2