org.scribe.model.Verifier Java Examples

The following examples show how to use org.scribe.model.Verifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Google2Api.java    From jpa-invoicer with The Unlicense 6 votes vote down vote up
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
    OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    switch (api.getAccessTokenVerb()) {
    case POST:
        request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
        request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
        request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
        request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
        request.addBodyParameter(GRANT_TYPE, GRANT_TYPE_AUTHORIZATION_CODE);
        break;
    case GET:
    default:
        request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
        request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
        request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
        request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
        if(config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
    }
    Response response = request.send();
    return api.getAccessTokenExtractor().extract(response.getBody());
}
 
Example #2
Source File: FacebookAuthController.java    From mamute with Apache License 2.0 6 votes vote down vote up
@Get("/sign-up/facebook/")
public void signupViaFacebook(String code, String state) {
	if (code == null) {
		includeAsList("mamuteMessages", i18n("error", "error.signup.facebook.unknown"));
		redirectTo(SignupController.class).signupForm();
		return;
	}
	
	Token token = service.getAccessToken(null, new Verifier(code));
	
	SocialAPI facebookAPI = new FacebookAPI(service, token);
	
	boolean success = loginManager.merge(MethodType.FACEBOOK, facebookAPI);
	if(!success) {
		includeAsList("mamuteMessages", i18n("error", "signup.errors.facebook.invalid_email", state));
		result.redirectTo(AuthController.class).loginForm(state);
		return;
	}
	redirectToRightUrl(state);
}
 
Example #3
Source File: HubicSwift.java    From swift-explorer with Apache License 2.0 6 votes vote down vote up
public static SwiftAccess getSwiftAccess ()
{
   	final HasAuthenticationSettings authSettings = Configuration.INSTANCE.getAuthenticationSettings() ;
	String apiKey = authSettings.getClientId() ;
	String apiSecret = authSettings.getClientSecret() ;

	HubicOAuth20ServiceImpl service = (HubicOAuth20ServiceImpl) new ServiceBuilder()
			.provider(HubicApi.class).apiKey(apiKey).apiSecret(apiSecret)
			//.scope("account.r,links.rw,usage.r,credentials.r").callback(HubicApi.CALLBACK_URL)
			.scope(scope).callback(HubicApi.CALLBACK_URL)
			.build();
	
	Verifier verif = service.obtainVerifier();
	
	if (verif == null)
		return null ;
	
	Token accessToken = service.getAccessToken(null, verif);
	return getSwiftAccess (service, accessToken) ;
}
 
Example #4
Source File: LoginActivity.java    From open with GNU General Public License v3.0 6 votes vote down vote up
private void setAccessToken(Intent intent) {
    Uri uri = intent.getData();
    verifier = new Verifier(uri.getQueryParameter(OSM_VERIFIER_KEY));
    (new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                app.setAccessToken(app.getOsmOauthService()
                        .getAccessToken(requestToken, verifier));
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Unable to log in", Toast.LENGTH_LONG).show();
            }

            return null;
        }
    }).execute();
}
 
Example #5
Source File: SliApi.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
public TokenResponse getAccessToken(Token requestToken, Verifier verifier, Token t) {
    TokenResponse tokenResponse = new TokenResponse();

    OAuthRequest request = new OAuthRequest(myApi.getAccessTokenVerb(), myApi.getAccessTokenEndpoint());
    request.addQuerystringParameter(OAuthConstants.CLIENT_ID, myConfig.getApiKey());
    request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, myConfig.getApiSecret());
    request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
    request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, myConfig.getCallback());
    if (myConfig.hasScope()) {
        request.addQuerystringParameter(OAuthConstants.SCOPE, myConfig.getScope());
    }

    Response response = request.send();

    tokenResponse.oauthResponse = response;
    tokenResponse.token = myApi.getAccessTokenExtractor().extract(response.getBody());
    return tokenResponse;
}
 
Example #6
Source File: BasicRESTClient.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public Response connect(final String authorizationCode) throws OAuthException, MalformedURLException,
        URISyntaxException {
    OAuthService service = new ServiceBuilder().provider(SliApi.class).apiKey(config.getApiKey())
            .apiSecret(config.getApiSecret()).callback(config.getCallback()).build();
    Verifier verifier = new Verifier(authorizationCode);
    SliApi.TokenResponse r = ((SliApi.SLIOauth20ServiceImpl) service).getAccessToken(
            new Token(config.getApiSecret(), authorizationCode), verifier, null);

    if (r != null && r.getToken() != null) {
        accessToken = r.getToken();
        sessionToken = accessToken.getToken();
    }

    ResponseBuilder builder = Response.status(r.getOauthResponse().getCode());
    for (Map.Entry<String, String> entry : r.getOauthResponse().getHeaders().entrySet()) {
        if (entry.getKey() == null) {
            builder.header("Status", entry.getValue());
        } else {
            builder.header(entry.getKey(), entry.getValue());
        }
    }
    builder.entity(r.getOauthResponse().getBody());

    return builder.build();
}
 
Example #7
Source File: WeiXinOAuth20ServiceImpl.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
/**
 * 获取account_token的http请求参数添加
 */
@Override
public Token getAccessToken(final Token requestToken, final Verifier verifier) {
    final OAuthRequest request = new ProxyOAuthRequest(this.api.getAccessTokenVerb(),
            this.api.getAccessTokenEndpoint(), this.connectTimeout,
            this.readTimeout, this.proxyHost, this.proxyPort);
    request.addBodyParameter("appid", this.config.getApiKey());
    request.addBodyParameter("secret", this.config.getApiSecret());
    request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
    request.addBodyParameter(OAuthConstants.REDIRECT_URI, this.config.getCallback());
    request.addBodyParameter("grant_type", "authorization_code");
    final Response response = request.send();
    return this.api.getAccessTokenExtractor().extract(response.getBody());
}
 
Example #8
Source File: LoginWindow.java    From jpa-invoicer with The Unlicense 5 votes vote down vote up
@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request,
        VaadinResponse response) throws IOException {
    if (request.getParameter("code") != null) {
        String code = request.getParameter("code");
        Verifier v = new Verifier(code);
        Token t = service.getAccessToken(null, v);

        OAuthRequest r = new OAuthRequest(Verb.GET,
                "https://www.googleapis.com/plus/v1/people/me");
        service.signRequest(t, r);
        Response resp = r.send();

        GooglePlusAnswer answer = new Gson().fromJson(resp.getBody(),
                GooglePlusAnswer.class);

        userSession.login(answer.emails[0].value, answer.displayName);

        close();
        VaadinSession.getCurrent().removeRequestHandler(this);

        ((VaadinServletResponse) response).getHttpServletResponse().
                sendRedirect(redirectUrl);
        return true;
    }

    return false;
}
 
Example #9
Source File: GoogleAuthController.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Get("/sign-up/google/")
public void signUpViaGoogle(String state, String code) {
	Token token = service.getAccessToken(null, new Verifier(code));
	SocialAPI googleAPI = new GoogleAPI(token, service);
    
	loginManager.merge(MethodType.GOOGLE, googleAPI);
	
    redirectToRightUrl(state);
}
 
Example #10
Source File: HubicOAuth20ServiceImpl.java    From swift-explorer with Apache License 2.0 5 votes vote down vote up
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {

	OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
	
	String authenticationCode = config.getApiKey() + ":" + config.getApiSecret() ;
	byte[] bytesEncodedAuthenticationCode = Base64.encodeBase64(authenticationCode.getBytes()); 
	request.addHeader ("Authorization", "Basic " + bytesEncodedAuthenticationCode) ;
	
	String charset = "UTF-8";
	
	request.setCharset(charset);
	request.setFollowRedirects(false);
	
	try
	{
		request.addBodyParameter(OAuthConstants.CODE, URLEncoder.encode(verifier.getValue(), charset));
		request.addBodyParameter(OAuthConstants.REDIRECT_URI, URLEncoder.encode(config.getCallback(), charset));
		request.addBodyParameter("grant_type", "authorization_code");
		request.addBodyParameter(OAuthConstants.CLIENT_ID, URLEncoder.encode(config.getApiKey(), charset));
		request.addBodyParameter(OAuthConstants.CLIENT_SECRET, URLEncoder.encode(config.getApiSecret(), charset));
	} 
	catch (UnsupportedEncodingException e) 
	{
		logger.error("Error occurred while getting the access token", e);
	}
	
	Response response = request.send();
	return api.getAccessTokenExtractor().extract(response.getBody());
}
 
Example #11
Source File: MainActivity.java    From FitbitAndroidSample with Apache License 2.0 5 votes vote down vote up
public void btnRetrieveData(View view) {
	EditText etPIN = (EditText) findViewById(R.id.etPIN);
	String gotPIN = etPIN.getText().toString();

	final Verifier v = new Verifier(gotPIN);

	// network operation shouldn't run on main thread
	new Thread(new Runnable() {
		public void run() {
			Token accessToken = service.getAccessToken(requestToken, v);

			OAuthRequest request = new OAuthRequest(Verb.GET,
					"http://api.fitbit.com/1/user/-/profile.json");
			service.signRequest(accessToken, request); // the access token from step
														// 4
			final Response response = request.send();
			final TextView tvOutput = (TextView) findViewById(R.id.tvOutput);

			// Visual output should run on main thread again...
			tvOutput.post(new Runnable() {
				@Override
				public void run() {
					tvOutput.setText(response.getBody());
				}
			});
		}
	}).start();
}
 
Example #12
Source File: SLIAuthenticationEntryPoint.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private void verifyingAuthentication(HttpServletRequest request, HttpServletResponse response, HttpSession session,
        OAuthService service) throws IOException {

    LOG.info(LOG_MESSAGE_AUTH_VERIFYING, new Object[] { request.getRemoteAddr() });

    Verifier verifier = new Verifier(request.getParameter(OAUTH_CODE));
    Token accessToken = service.getAccessToken(null, verifier);
    session.setAttribute(OAUTH_TOKEN, accessToken.getToken());
    Object entryUrl = session.getAttribute(ENTRY_URL);
    if (entryUrl != null) {
        response.sendRedirect(session.getAttribute(ENTRY_URL).toString());
    } else {
        response.sendRedirect(request.getRequestURI());
    }
}
 
Example #13
Source File: EvernoteOAuthActivity.java    From EverMemo with MIT License 5 votes vote down vote up
@Override
protected EvernoteAuthToken doInBackground(Uri... uris) {
	EvernoteAuthToken authToken = null;
	if (uris == null || uris.length == 0) {
		return null;
	}
	Uri uri = uris[0];

	if (!TextUtils.isEmpty(mRequestToken)) {
		OAuthService service = createService();
		String verifierString = uri.getQueryParameter("oauth_verifier");
		if (TextUtils.isEmpty(verifierString)) {
			Log.i(LOGTAG, "User did not authorize access");
		} else {
			Verifier verifier = new Verifier(verifierString);
			Log.i(LOGTAG, "Retrieving OAuth access token...");
			try {
				Token reqToken = new Token(mRequestToken,
						mRequestTokenSecret);
				authToken = new EvernoteAuthToken(
						service.getAccessToken(reqToken, verifier));
			} catch (Exception ex) {
				Log.e(LOGTAG, "Failed to obtain OAuth access token", ex);
			}
		}
	} else {
		Log.d(LOGTAG,
				"Unable to retrieve OAuth access token, no request token");
	}

	return authToken;
}
 
Example #14
Source File: EvernoteOAuthActivity.java    From EverMemo-EverNote with MIT License 5 votes vote down vote up
@Override
protected EvernoteAuthToken doInBackground(Uri... uris) {
  EvernoteAuthToken authToken = null;
  if (uris == null || uris.length == 0) {
    return null;
  }
  Uri uri = uris[0];

  if (!TextUtils.isEmpty(mRequestToken)) {
    OAuthService service = createService();
    String verifierString = uri.getQueryParameter("oauth_verifier");
    if (TextUtils.isEmpty(verifierString)) {
      Log.i(LOGTAG, "User did not authorize access");
    } else {
      Verifier verifier = new Verifier(verifierString);
      Log.i(LOGTAG, "Retrieving OAuth access token...");
      try {
        Token reqToken = new Token(mRequestToken, mRequestTokenSecret);
        authToken = new EvernoteAuthToken(service.getAccessToken(reqToken, verifier));
      } catch (Exception ex) {
        Log.e(LOGTAG, "Failed to obtain OAuth access token", ex);
      }
    }
  } else {
    Log.d(LOGTAG, "Unable to retrieve OAuth access token, no request token");
  }

  return authToken;
}
 
Example #15
Source File: ResourceClient.java    From jerseyoauth2 with MIT License 4 votes vote down vote up
public Token getAccessToken(String code) {
	OAuthService service = getOAuthService(scopes, null);
	return service.getAccessToken(null, new Verifier(code));
}
 
Example #16
Source File: OAuth2ServiceWrapper.java    From jerseyoauth2 with MIT License 4 votes vote down vote up
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
	return wrapped.getAccessToken(requestToken, verifier);
}