當前位置: 首頁>>代碼示例>>Java>>正文


Java TokenResult類代碼示例

本文整理匯總了Java中org.glassfish.jersey.client.oauth2.TokenResult的典型用法代碼示例。如果您正苦於以下問題:Java TokenResult類的具體用法?Java TokenResult怎麽用?Java TokenResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TokenResult類屬於org.glassfish.jersey.client.oauth2包,在下文中一共展示了TokenResult類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: callback

import org.glassfish.jersey.client.oauth2.TokenResult; //導入依賴的package包/類
@GET
@Path("/callback")
public Response callback(@Context HttpServletRequest request, @Context UriInfo uriInfo, @QueryParam("code") String code, @QueryParam("state") String state) {

    if (code == null) {
        if (log.isWarnEnabled()) { log.warn("Authorization Code is null, failed oauth2 callback"); }
        return Response.status(Response.Status.BAD_REQUEST).entity("Authorization code required").build();
    } // end if

    if (state == null) {
        if (log.isWarnEnabled()) { log.warn("State is null, failed oauth2 callback"); }
        return Response.status(Response.Status.BAD_REQUEST).entity("Missing state string").build();
    } // end if

    /*** RETRIEVE FROM SESSION TO CLOSE OUT THE FLOW ***/
    OAuth2CodeGrantFlow flow = (OAuth2CodeGrantFlow)request.getSession().getAttribute(getFlowSessionKey());
    String instanceID = (String)request.getSession().getAttribute(getInstanceIDSessionKey());
    String userID =  (String)request.getSession().getAttribute(getUserIDSessionKey());

    if (JiveSDKUtils.isAllExist(instanceID, userID, flow)) {

        TokenResult tokenResult = flow.finish(code,state);

        if (log.isDebugEnabled()) { log.debug("Successfully Retrieved OAuth Tokens["+SERVICE_NAME+"]: instanceID="+instanceID+", code="+code+", result="+tokenResult); }

        try {
            URI uri = new URI("/oauth/google/callback-close.jsp");
            return Response.temporaryRedirect(uri).build();
        } catch (URISyntaxException use) {
            log.error("Invalid Authorization URI: /oauth/google/callback-close.jsp",use);
            return Response.serverError().entity("Invalid Close URL").build();
        } // end try/catch

    } // end if
    return Response.status(404).entity("Resource Not Found").build();
}
 
開發者ID:jivesoftware,項目名稱:jive-sdk-java-jersey,代碼行數:37,代碼來源:GoogleOAuth2Service.java

示例2: getOAuth2GrantSuccessData

import org.glassfish.jersey.client.oauth2.TokenResult; //導入依賴的package包/類
protected Map<String, Object> getOAuth2GrantSuccessData(String instanceID, String userID, String code, TokenResult tokens) {
    Map data = Maps.newHashMap();

    initOAuthSuccessEventData(data, instanceID, userID);

    data.put("oauth2.code",code);
    data.put("oauth2.tokens",tokens);

    if (getOAuthVersion() != 2) {
        log.warn("OAuth Service declares OAuthVersion != 2, expected 2 with call to getOAuth2GrantSuccessData");
    } // end if

    return data;
}
 
開發者ID:jivesoftware,項目名稱:jive-sdk-java-jersey,代碼行數:15,代碼來源:BaseOAuthService.java

示例3: simpleResourceTest

import org.glassfish.jersey.client.oauth2.TokenResult; //導入依賴的package包/類
@Test
public void simpleResourceTest() throws UnsupportedEncodingException
{
	
	ClientIdentifier cliendId = new ClientIdentifier(clientEntity.getClientId(), clientEntity.getClientSecret());
	
	Builder<?> flowBuilder = OAuth2ClientSupport.authorizationCodeGrantFlowBuilder(cliendId, "http://localhost:9998/testsuite/oauth2/auth", "http://localhost:9998/testsuite/oauth2/accessToken");
	OAuth2CodeGrantFlow flow = flowBuilder.scope("test1 test2").redirectUri("http://localhost:9998/testsuite").build();
	String authUrl = flow.start();
	
	Map<String, String> map = retrieveCode(authUrl);
	String code = map.get("code");
	String state = map.get("state"); 
	
	TokenResult tokenResult = flow.finish(code, state);

	client = ClientBuilder.newClient();
	client.register(LoggingFilter.class);
	client.register(OAuth2ClientSupport.feature(tokenResult.getAccessToken()));
	client.register(JacksonFeature.class);
	Invocation.Builder builder = client.target("http://localhost:9998/testsuite/rest/sample/1").request();
	Response response = builder.get();
	
	assertEquals(200, response.getStatus());
	SampleEntity entity = response.readEntity(SampleEntity.class);
	assertNotNull(entity);
}
 
開發者ID:hburgmeier,項目名稱:jerseyoauth2,代碼行數:28,代碼來源:Jersey2Test.java

示例4: updateTokens

import org.glassfish.jersey.client.oauth2.TokenResult; //導入依賴的package包/類
private void updateTokens(final TokenResult result) {
    refreshToken = result.getRefreshToken();
    String accessToken = result.getAccessToken();
    long validUntil = System.currentTimeMillis() + result.getExpiresIn() * 1000 - 5000;
    ACCESS_TOKEN_CACHE.put(getAuthKey(), new AccessTokenData(accessToken, validUntil));
}
 
開發者ID:burberius,項目名稱:eve-esi,代碼行數:7,代碼來源:OAuth.java

示例5: callback

import org.glassfish.jersey.client.oauth2.TokenResult; //導入依賴的package包/類
@GET
@Path("/callback")
public Response callback(@Context HttpServletRequest request, @Context UriInfo uriInfo,
                         @QueryParam("code") String code, @QueryParam("state") String state,
                         @QueryParam("error") String error, @QueryParam("error_description") String description,
                         @QueryParam("error_reason") String reason) {

    if (error != null) {
        /*** RETRIEVE FROM SESSION TO CLOSE OUT THE FLOW ***/
        request.getSession().removeAttribute(getFlowSessionKey());
        request.getSession().removeAttribute(getInstanceIDSessionKey());
        request.getSession().removeAttribute(getUserIDSessionKey());

        if (log.isDebugEnabled()) { log.debug("Callback Error: error:"+error+", description:"+description+", reason:"+reason); }

        return Response.serverError().entity("error:"+error+", description:"+description+", reason:"+reason).build();
    } // end if

    if (code == null) {
        System.out.println("Code is null");
        return Response.status(Response.Status.BAD_REQUEST).entity("Authorization code required").build();
    } // end if

    if (state == null) {
        System.out.println("State is null");
        return Response.status(Response.Status.BAD_REQUEST).entity("Missing state string").build();
    } // end if

    /*** RETRIEVE FROM SESSION TO CLOSE OUT THE FLOW ***/
    OAuth2CodeGrantFlow flow = (OAuth2CodeGrantFlow)request.getSession().getAttribute(getFlowSessionKey());
    String instanceID = (String)request.getSession().getAttribute(getInstanceIDSessionKey());
    String userID =  (String)request.getSession().getAttribute(getUserIDSessionKey());

    if (JiveSDKUtils.isAllExist(instanceID, userID, flow)) {

        TokenResult tokenResult = flow.finish(code,state);

        if (log.isDebugEnabled()) { log.debug("Successfully Retrieved OAuth Tokens["+SERVICE_NAME+"]: instanceID="+instanceID+", code="+code+", result="+tokenResult); }
        fireOAuthEvent(OAuthEvent.Type.GrantSuccess,getOAuth2GrantSuccessData(instanceID, userID, code, tokenResult));

        try {
            URI uri = new URI("/oauth/"+SERVICE_NAME+"/callback-close.jsp");
            return Response.temporaryRedirect(uri).build();
        } catch (URISyntaxException use) {
            log.error("Invalid Authorization URI: /oauth/"+SERVICE_NAME+"/callback-close.jsp",use);
            return Response.serverError().entity("Invalid Close URL").build();
        } // end try/catch

    } // end if
    return Response.status(404).entity("Resource Not Found").build();
}
 
開發者ID:jivesoftware,項目名稱:jive-sdk-java-jersey,代碼行數:52,代碼來源:FacebookOAuth2Service.java

示例6: callback

import org.glassfish.jersey.client.oauth2.TokenResult; //導入依賴的package包/類
@GET
@Path("/callback")
public Response callback(@Context HttpServletRequest request, @Context UriInfo uriInfo,
                         @QueryParam("code") String code, @QueryParam("state") String state) {

    if (code == null) {
        if (log.isWarnEnabled()) { log.warn("Authorization Code is null, failed oauth2 callback"); }
        return Response.status(Response.Status.BAD_REQUEST).entity("Authorization code required").build();
    } // end if

    if (state == null) {
        if (log.isWarnEnabled()) { log.warn("State is null, failed oauth2 callback"); }
        return Response.status(Response.Status.BAD_REQUEST).entity("Missing state string").build();
    } // end if

    /*** RETRIEVE FROM SESSION TO CLOSE OUT THE FLOW ***/
    OAuth2CodeGrantFlow flow = (OAuth2CodeGrantFlow)request.getSession().getAttribute(getFlowSessionKey());
    String instanceID = (String)request.getSession().getAttribute(getInstanceIDSessionKey());
    String userID =  (String)request.getSession().getAttribute(getUserIDSessionKey());

    if (JiveSDKUtils.isAllExist(instanceID, userID, flow)) {

        TokenResult tokenResult = flow.finish(code,state);

        if (log.isDebugEnabled()) { log.debug("Successfully Retrieved OAuth Tokens["+SERVICE_NAME+"]: instanceID="+instanceID+", code="+code+", result="+tokenResult); }
        fireOAuthEvent(OAuthEvent.Type.GrantSuccess,getOAuth2GrantSuccessData(instanceID, userID, code, tokenResult));

        try {
            URI uri = new URI("/oauth/"+SERVICE_NAME+"/callback-close.jsp");
            return Response.temporaryRedirect(uri).build();
        } catch (URISyntaxException use) {
            log.error("Invalid Authorization URI: /oauth/"+SERVICE_NAME+"/callback-close.jsp",use);
            return Response.serverError().entity("Invalid Close URL").build();
        } // end try/catch

    } else {
        if (log.isWarnEnabled()) { log.warn("Missing Required Data instanceID["+instanceID+"], userID["+userID+"]"); }
    } // end if

    return Response.status(404).entity("Resource Not Found").build();
}
 
開發者ID:jivesoftware,項目名稱:jive-sdk-java-jersey,代碼行數:42,代碼來源:JiveOAuth2Service.java


注:本文中的org.glassfish.jersey.client.oauth2.TokenResult類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。