Package org.scribe.model

Examples of org.scribe.model.Token


     * {@inheritDoc}
     */
    @Override
    protected OAuthCredentials getOAuthCredentials(final WebContext context) {
        // get tokenRequest from session
        final Token tokenRequest = (Token) context.getSessionAttribute(getRequestTokenSessionAttributeName());
        logger.debug("tokenRequest : {}", tokenRequest);
        // don't get parameters from url
        // token and verifier are equals and extracted from saved request token
        final String token = tokenRequest.getToken();
        logger.debug("token = verifier : {}", token);
        return new OAuthCredentials(tokenRequest, token, token, getName());
    }
View Full Code Here


        return getName() + "#" + REQUEST_TOKEN;
    }
   
    @Override
    protected String retrieveAuthorizationUrl(final WebContext context) {
        final Token requestToken = this.service.getRequestToken();
        logger.debug("requestToken : {}", requestToken);
        // save requestToken in user session
        context.setSessionAttribute(getRequestTokenSessionAttributeName(), requestToken);
        final String authorizationUrl = this.service.getAuthorizationUrl(requestToken);
        logger.debug("authorizationUrl : {}", authorizationUrl);
View Full Code Here

    protected OAuthCredentials getOAuthCredentials(final WebContext context) {
        final String tokenParameter = context.getRequestParameter(OAUTH_TOKEN);
        final String verifierParameter = context.getRequestParameter(OAUTH_VERIFIER);
        if (tokenParameter != null && verifierParameter != null) {
            // get request token from session
            final Token tokenSession = (Token) context.getSessionAttribute(getRequestTokenSessionAttributeName());
            logger.debug("tokenRequest : {}", tokenSession);
            final String token = OAuthEncoder.decode(tokenParameter);
            final String verifier = OAuthEncoder.decode(verifierParameter);
            logger.debug("token : {} / verifier : {}", token, verifier);
            return new OAuthCredentials(tokenSession, token, verifier, getName());
View Full Code Here

    /**
     * {@inheritDoc}
     */
    @Override
    protected Token getAccessToken(final OAuthCredentials credentials) {
        final Token tokenRequest = credentials.getRequestToken();
        final String token = credentials.getToken();
        final String verifier = credentials.getVerifier();
        logger.debug("tokenRequest : {}", tokenRequest);
        logger.debug("token : {}", token);
        logger.debug("verifier : {}", verifier);
        if (tokenRequest == null) {
            final String message = "Token request expired";
            logger.error(message);
            throw new OAuthCredentialsException(message);
        }
        final String savedToken = tokenRequest.getToken();
        logger.debug("savedToken : {}", savedToken);
        if (savedToken == null || !savedToken.equals(token)) {
            final String message = "Token received : " + token + " is different from saved token : " + savedToken;
            logger.error(message);
            throw new OAuthCredentialsException(message);
        }
        final Verifier clientVerifier = new Verifier(verifier);
        final Token accessToken = this.service.getAccessToken(tokenRequest, clientVerifier);
        logger.debug("accessToken : {}", accessToken);
        return accessToken;
    }
View Full Code Here

   
    public Token extract(final String response) {
        Preconditions.checkEmptyString(response, "Cannot extract a token from a null or empty String");
        final Matcher matcher = this.accessTokenPattern.matcher(response);
        if (matcher.find()) {
            return new Token(matcher.group(1), "", response);
        } else {
            throw new OAuthException("Cannot extract an acces token. Response was: " + response);
        }
    }
View Full Code Here

   
    public Token extract(final String response) {
        Preconditions.checkEmptyString(response, "Cannot extract a token from a null or empty String");
        final Matcher matcher = this.accessTokenPattern.matcher(response);
        if (matcher.find()) {
            return new Token(matcher.group(1), "", response);
        } else {
            throw new OAuthException("Cannot extract an acces token. Response was: " + response);
        }
    }
View Full Code Here

     * @return the user profile
     */
    @Override
    protected U retrieveUserProfile(final OAuthCredentials credentials, final WebContext context) {
        try {
            final Token token = getAccessToken(credentials);
            return retrieveUserProfileFromToken(token);
        } catch (final OAuthException e) {
            throw new TechnicalException(e);
        }
    }
View Full Code Here

     * @return the user profile
     */
    public U getUserProfile(final String accessToken) {
        init();
        try {
            final Token token = new Token(accessToken, "");
            return retrieveUserProfileFromToken(token);
        } catch (final OAuthException e) {
            throw new TechnicalException(e);
        }
    }
View Full Code Here

     * @param dataUrl
     * @return the body of the requested resource
     */
    public String sendRequestForData(final OAuth10Profile profile, final String dataUrl) {
        final String secret = profile.getAccessSecret();
        final Token accessToken = new Token(profile.getAccessToken(), secret == null ? "" : secret);
        return sendRequestForData(accessToken, dataUrl);
    }
View Full Code Here

    public void testOAuthCredentials() {
        final OAuthCredentials credentials = new OAuthCredentials(REQUEST_TOKEN, TOKEN, VERIFIER, TYPE);
        assertEquals(TOKEN, credentials.getToken());
        assertEquals(VERIFIER, credentials.getVerifier());
        assertEquals(TYPE, credentials.getClientName());
        final Token requestToken = credentials.getRequestToken();
        assertEquals(TOKEN, requestToken.getToken());
        assertEquals(SECRET, requestToken.getSecret());
        // test serialization
        final byte[] bytes = TestsHelper.serialize(credentials);
        final OAuthCredentials credentials2 = (OAuthCredentials) TestsHelper.unserialize(bytes);
        assertEquals(credentials.getRequestToken().toString(), credentials2.getRequestToken().toString());
        assertEquals(credentials.getToken(), credentials2.getToken());
View Full Code Here

TOP

Related Classes of org.scribe.model.Token

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.