本文整理汇总了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();
}
示例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;
}
示例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);
}
示例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));
}
示例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();
}
示例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();
}