use of com.github.scribejava.core.model.OAuthRequest in project scribejava by scribejava.
the class OdnoklassnikiServiceTest method testSigGeneration.
@Test
public void testSigGeneration() {
final OAuth2AccessToken accessToken = new OAuth2AccessToken("d3iwa.403gvrs194740652m1k4w2a503k3c");
final OAuthRequest request = new OAuthRequest(Verb.GET, URL);
service.signRequest(accessToken, request);
assertEquals("96127f5ca29a8351399e94bbd284ab16", findParam(request.getQueryStringParams(), "sig"));
}
use of com.github.scribejava.core.model.OAuthRequest in project pac4j by pac4j.
the class OAuthProfileCreator method sendRequestForData.
/**
* Make a request to get the data of the authenticated user for the provider.
*
* @param service the OAuth service
* @param accessToken the access token
* @param dataUrl url of the data
* @param verb method used to request data
* @return the user data response
*/
protected String sendRequestForData(final S service, final T accessToken, final String dataUrl, Verb verb) {
logger.debug("accessToken: {} / dataUrl: {}", accessToken, dataUrl);
final long t0 = System.currentTimeMillis();
final OAuthRequest request = createOAuthRequest(dataUrl, verb);
signRequest(service, accessToken, request);
final String body;
final int code;
try {
Response response = service.execute(request);
code = response.getCode();
body = response.getBody();
} catch (final IOException | InterruptedException | ExecutionException e) {
throw new HttpCommunicationException("Error getting body: " + e.getMessage());
}
final long t1 = System.currentTimeMillis();
logger.debug("Request took: " + (t1 - t0) + " ms for: " + dataUrl);
logger.debug("response code: {} / response body: {}", code, body);
if (code != 200) {
throw new HttpCommunicationException(code, body);
}
return body;
}
use of com.github.scribejava.core.model.OAuthRequest in project dataverse by IQSS.
the class OrcidOAuth2AP method getUserRecord.
@Override
public OAuth2UserRecord getUserRecord(String code, String state, String redirectUrl) throws IOException, OAuth2Exception {
OAuth20Service service = getService(state, redirectUrl);
OAuth2AccessToken accessToken = service.getAccessToken(code);
if (!accessToken.getScope().contains(scope)) {
// We did not get the permissions on the scope we need. Abort and inform the user.
throw new OAuth2Exception(200, BundleUtil.getStringFromBundle("auth.providers.orcid.insufficientScope"), "");
}
String orcidNumber = extractOrcidNumber(accessToken.getRawResponse());
final String userEndpoint = getUserEndpoint(accessToken);
final OAuthRequest request = new OAuthRequest(Verb.GET, userEndpoint, service);
request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken());
request.setCharset("UTF-8");
final Response response = request.send();
int responseCode = response.getCode();
final String body = response.getBody();
logger.log(Level.FINE, "In getUserRecord. Body: {0}", body);
if (responseCode == 200) {
final ParsedUserResponse parsed = parseUserResponse(body);
AuthenticatedUserDisplayInfo orgData = getOrganizationalData(userEndpoint, accessToken.getAccessToken(), service);
parsed.displayInfo.setAffiliation(orgData.getAffiliation());
parsed.displayInfo.setPosition(orgData.getPosition());
return new OAuth2UserRecord(getId(), orcidNumber, parsed.username, OAuth2TokenData.from(accessToken), parsed.displayInfo, parsed.emails);
} else {
throw new OAuth2Exception(responseCode, body, "Error getting the user info record.");
}
}
use of com.github.scribejava.core.model.OAuthRequest in project adeptj-modules by AdeptJ.
the class OAuth2CallbackServlet method processRequest.
private void processRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String code = req.getParameter("code");
LOGGER.info("OAuth2 code: [{}]", code);
String provider = StringUtils.substringAfterLast(req.getRequestURI(), "/");
LOGGER.info("Provider: [{}]", provider);
OAuth20Service oAuth2Service = this.providerFactory.getOAuth2Service(provider);
OAuth2AccessToken token = null;
try {
token = oAuth2Service.getAccessToken(code);
LOGGER.info("OAuth2AccessToken: [{}]", token);
OAuthRequest oReq = new OAuthRequest(Verb.GET, "https://api.linkedin.com/v1/people/~?format=json");
oAuth2Service.signRequest(token, oReq);
Response oResp = oAuth2Service.execute(oReq);
LOGGER.info("Linkedin Profile: [{}]", oResp.getBody());
resp.getOutputStream().write(oResp.getBody().getBytes(StandardCharsets.UTF_8));
} catch (InterruptedException | ExecutionException ex) {
}
}
use of com.github.scribejava.core.model.OAuthRequest in project scribejava by scribejava.
the class MicrosoftAzureActiveDirectoryExample method main.
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
// Replace these with your client id and secret
final String clientId = "client id here";
final String clientSecret = "client secret here";
final OAuth20Service service = new ServiceBuilder(clientId).apiSecret(clientSecret).scope("openid").callback("http://www.example.com/oauth_callback/").build(MicrosoftAzureActiveDirectoryApi.instance());
final Scanner in = new Scanner(System.in, "UTF-8");
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
final String authorizationUrl = service.getAuthorizationUrl();
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize ScribeJava here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
final String code = in.nextLine();
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
final OAuth2AccessToken accessToken = service.getAccessToken(code);
System.out.println("Got the Access Token!");
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
final Response response = service.execute(request);
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
}
Aggregations