Search in sources :

Example 26 with OAuth10aService

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;
}
Also used : OAuth1AccessToken(com.github.scribejava.core.model.OAuth1AccessToken) OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) OAuth10aService(com.github.scribejava.core.oauth.OAuth10aService)

Example 27 with OAuth10aService

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());
            }
        }
    });
}
Also used : OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) OAuthException(com.github.scribejava.core.exceptions.OAuthException) AsyncSimpleTask(com.codepath.utils.AsyncSimpleTask) OAuth10aService(com.github.scribejava.core.oauth.OAuth10aService) Uri(android.net.Uri) OAuthException(com.github.scribejava.core.exceptions.OAuthException) OAuth20Service(com.github.scribejava.core.oauth.OAuth20Service)

Example 28 with OAuth10aService

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;
}
Also used : RedirectView(org.springframework.web.servlet.view.RedirectView) OAuth10aService(com.github.scribejava.core.oauth.OAuth10aService) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

OAuth10aService (com.github.scribejava.core.oauth.OAuth10aService)28 OAuth1RequestToken (com.github.scribejava.core.model.OAuth1RequestToken)24 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)21 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)21 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)20 Response (com.github.scribejava.core.model.Response)20 Scanner (java.util.Scanner)20 OAuthException (com.github.scribejava.core.exceptions.OAuthException)3 AsyncSimpleTask (com.codepath.utils.AsyncSimpleTask)2 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)2 HttpCommunicationException (org.pac4j.core.exception.HttpCommunicationException)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Uri (android.net.Uri)1 MediaWikiApi (com.github.scribejava.apis.MediaWikiApi)1 Token (com.github.scribejava.core.model.Token)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 PostConstruct (javax.annotation.PostConstruct)1 TechnicalException (org.pac4j.core.exception.TechnicalException)1 OAuth10ProfileDefinition (org.pac4j.oauth.profile.definition.OAuth10ProfileDefinition)1