Examples of OauthToken


Examples of com.cloudbees.api.oauth.OauthToken

            params.put("grant_type", singletonList("refresh_token"));
            params.put("refresh_token", singletonList(refreshToken));
            if (scopes!=null)
                params.put("scope", singletonList(join(Arrays.asList(scopes),",")));

            OauthToken resp = bees.formUrlEncoded(gcUrl+"/oauth/token", null, params).bind(OauthToken.class,bees);
            return resp;
        } catch (IOException e) {
            throw new OauthClientException("Failed to exchange authorization code to access token",e);
        }
    }
View Full Code Here

Examples of com.cloudbees.api.oauth.OauthToken

        if (token == null) {
            logger.error("No OAuth access_token found in the request.");
            throw new AuthException(401, "No OAuth access_token found in the request.");
        }

        OauthToken oauthToken;
        try {
            //Validate scopes
            if(secureAnnotation.validateAllScopes()){
                oauthToken = oauthClient.validateToken(token);
                if(oauthToken != null){
                    for(String scope:scopes){
                        if(!oauthToken.validateScope(scope)){
                            throw new AuthException(401, String.format("Expected scope: %s not found on the token", scope));
                        }
                    }
                }
            }else{
View Full Code Here

Examples of com.cloudbees.api.oauth.OauthToken

            throw new OauthClientException("Failed to validate token. "+e.getMessage(), e);
        }
    }

    private OauthToken toToken(OauthTokenDetail resp) {
        OauthToken token = new OauthToken();
        token.owner = this;
        token.refreshToken = resp.refreshToken != null ? resp.refreshToken.token : null;
        token.accessToken = resp.accessToken.token;
        token.setAccount(resp.account);
        token.scope = join(resp.accessToken.scopes,",");
        token.tokenType = resp.accessToken.tokenType;
        token.uid = resp.uid;
        token.email = resp.email;
        token.setExpiresIn(resp.accessToken.expiresIn);
        token.id = resp.id;
        return token;
    }
View Full Code Here

Examples of com.cloudbees.api.oauth.OauthToken

            throw new OauthClientException("Failed to delete OAuth token",e);
        }
    }

    public OauthToken validateToken(String token, String... scopes) throws OauthClientException {
        OauthToken oauthToken = validateToken(token);
        if (oauthToken==null)   return null;

        if (oauthToken.validateScopes(scopes))
            return oauthToken;
        else
            return null;
    }
View Full Code Here

Examples of com.cloudbees.api.oauth.OauthToken

            return null;
    }

    public OauthToken validateToken(String token) throws OauthClientException {
        try{
            OauthToken oauthToken = bees.jsonPOJORequest(gcUrl+"/oauth/tokens/"+token,null,OauthToken.class,"GET");

            if(oauthToken.isExpired()){
                return null;
            }
            return oauthToken;
        }catch (IOException e){
            logger.log(Level.WARNING, "Failed to get token details",e);
View Full Code Here

Examples of com.cloudbees.api.oauth.OauthToken

        this.account = account;
    }

    @Override
    public OauthToken createToken(TokenRequest r) throws OauthClientException {
        OauthToken t = new OauthToken();
        t.accessToken = "account="+r.getAccountName()+",scope="+ join(r.getScopes(), " ");
        return t;
    }
View Full Code Here

Examples of com.cloudbees.api.oauth.OauthToken

        return t;
    }

    @Override
    public OauthToken createOAuthClientToken(Collection<String> scopes) throws OauthClientException {
        OauthToken t = new OauthToken();
        t.accessToken = "account="+account+",scope="+ join(scopes, " ");
        return t;
    }
View Full Code Here

Examples of com.cloudbees.api.oauth.OauthToken

        // cue to return null?
        if (token.startsWith("invalid"))
            return null;

        OauthToken oa = new OauthToken();
        for (String t : token.split(",")) {
            String[] lr = t.split("=");
            if (lr.length!=2)
                throw new IllegalArgumentException("Malformed mock token: "+t);
View Full Code Here

Examples of com.cloudbees.api.oauth.OauthToken

            throw new OauthClientException("Failed to create token. "+e.getMessage(), e);
        }
    }

    private OauthToken toToken(OauthTokenDetail resp) {
        OauthToken token = new OauthToken();
        token.owner = this;
        token.refreshToken = resp.refreshToken != null ? resp.refreshToken.token : null;
        token.accessToken = resp.accessToken.token;
        token.setAccount(resp.account);
        token.scope = join(resp.accessToken.scopes,",");
        token.tokenType = resp.accessToken.tokenType;
        token.uid = resp.uid;
        token.email = resp.email;
        token.userAccountRole = resp.userAccountRole;

        token.setExpiresIn(resp.accessToken.expiresIn);
        token.id = resp.id;
        return token;
    }
View Full Code Here

Examples of com.cloudbees.api.oauth.OauthToken

            throw new OauthClientException("Failed to delete OAuth token",e);
        }
    }

    public OauthToken validateToken(String token, String... scopes) throws OauthClientException {
        OauthToken oauthToken = validateToken(token);
        if (oauthToken==null)   return null;

        if (oauthToken.validateScopes(scopes))
            return oauthToken;
        else
            return null;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.