use of com.github.scribejava.core.oauth.OAuth10aService in project wikidata-query-rdf by wikimedia.
the class OAuthProxyServiceUnitTest method getMockedMWOAuthService.
private OAuth10aService getMockedMWOAuthService() throws IOException, InterruptedException, ExecutionException {
OAuth10aService mwoauthServiceMock = mock(OAuth10aService.class);
OAuth1RequestToken requestToken = new OAuth1RequestToken(OAUTH_TOKEN_STRING, "tokenSecret");
when(mwoauthServiceMock.getRequestToken()).thenReturn(requestToken);
when(mwoauthServiceMock.getAuthorizationUrl(requestToken)).thenReturn(AUTHORIZE_URL);
OAuth1AccessToken accessToken = new OAuth1AccessToken("access_token", "access_token_secret");
when(mwoauthServiceMock.getAccessToken(requestToken, OAUTH_VERIFIER_STR)).thenReturn(accessToken);
return mwoauthServiceMock;
}
use of com.github.scribejava.core.oauth.OAuth10aService in project android-oauth-handler by codepath.
the class OAuthAsyncHttpClient method fetchAccessToken.
// Get the access token by exchanging the requestToken to the defined URL
// Once receiving the access token, fires the onReceivedAccessToken method on the handler
public void fetchAccessToken(final Token requestToken, final Uri uri) {
new AsyncSimpleTask(new AsyncSimpleTask.AsyncSimpleTaskHandler() {
Exception e = null;
public void doInBackground() {
// Fetch the verifier code from redirect url parameters
Uri authorizedUri = uri;
try {
if (service.getVersion() == "1.0") {
if (authorizedUri.getQuery().contains(OAuthConstants.VERIFIER)) {
String oauth_verifier = authorizedUri.getQueryParameter(OAuthConstants.VERIFIER);
OAuth1RequestToken oAuth1RequestToken = (OAuth1RequestToken) requestToken;
OAuth10aService oAuth10aService = (OAuth10aService) service;
accessToken = oAuth10aService.getAccessToken(oAuth1RequestToken, oauth_verifier);
} else {
// verifier was null
throw new OAuthException("No verifier code was returned with uri '" + uri + "' " + "and access token cannot be retrieved");
}
} else if (service.getVersion() == "2.0") {
if (authorizedUri.getQuery().contains(OAuthConstants.CODE)) {
String code = authorizedUri.getQueryParameter(OAuthConstants.CODE);
OAuth20Service oAuth20Service = (OAuth20Service) service;
accessToken = oAuth20Service.getAccessToken(code);
} else {
// verifier was null
throw new OAuthException("No code was returned with uri '" + uri + "' " + "and access token cannot be retrieved");
}
}
} catch (Exception e) {
this.e = e;
}
}
public void onPostExecute() {
if (e != null) {
handler.onFailure(e);
} else {
setAccessToken(accessToken);
handler.onReceivedAccessToken(accessToken, service.getVersion());
}
}
});
}
use of com.github.scribejava.core.oauth.OAuth10aService in project tutorials by eugenp.
the class TwitterController method authorization.
@GetMapping(value = "/authorization")
public RedirectView authorization(HttpServletRequest servletReq) throws InterruptedException, ExecutionException, IOException {
OAuth10aService twitterService = createService();
OAuth1RequestToken requestToken = twitterService.getRequestToken();
String authorizationUrl = twitterService.getAuthorizationUrl(requestToken);
servletReq.getSession().setAttribute("requestToken", requestToken);
RedirectView redirectView = new RedirectView();
redirectView.setUrl(authorizationUrl);
return redirectView;
}
Aggregations