本文整理汇总了Java中com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl类的典型用法代码示例。如果您正苦于以下问题:Java AuthorizationCodeResponseUrl类的具体用法?Java AuthorizationCodeResponseUrl怎么用?Java AuthorizationCodeResponseUrl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuthorizationCodeResponseUrl类属于com.google.api.client.auth.oauth2包,在下文中一共展示了AuthorizationCodeResponseUrl类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onError
import com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl; //导入依赖的package包/类
@Override
protected void onError(HttpServletRequest req, HttpServletResponse resp, AuthorizationCodeResponseUrl errorResponse) throws IOException {
String callbackUrl = (String) req.getSession().getAttribute("callbackUrl");
if(callbackUrl == null) {
BufferedOutputStream bos = new BufferedOutputStream(resp.getOutputStream());
PrintWriter pw = new PrintWriter(bos);
resp.setContentType("application/json");
resp.setHeader("access-control-allow-origin", "*");
pw.print(String.format(
"{\"error\": {\"code\": \"%s\", \"errorMessage\": \"%s\", \"errorDescription\": \"%s\", \"errorUri\": \"%s\", \"state\": \"%s\"}}",
errorResponse.getCode(),
errorResponse.getError(),
errorResponse.getErrorDescription(),
errorResponse.getErrorUri(),
errorResponse.getState()
));
pw.close();
} else {
resp.sendRedirect(callbackUrl + "?notLoggedIn=true");
req.getSession().removeAttribute("callbackUrl");
}
}
开发者ID:melchor629,项目名称:agendamlgr,代码行数:23,代码来源:OAuthCallbackServlet.java
示例2: doGet
import com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String requestUrl = req.getRequestURL().append('?').append(req.getQueryString()).toString();
AuthorizationCodeResponseUrl authorizationCodeResponseUrl =
new AuthorizationCodeResponseUrl(requestUrl);
if (authorizationCodeResponseUrl.getError() != null) {
throw new IOException("Received error: " + authorizationCodeResponseUrl.getError());
} else {
// Authenticate the user and store their credential with their user ID (derived from
// the request).
HttpSession httpSession = req.getSession(true);
if (httpSession.getAttribute(Server.USER_SESSION_ID) == null) {
httpSession.setAttribute(Server.USER_SESSION_ID, new Random().nextLong());
}
String authorizationCode = authorizationCodeResponseUrl.getCode();
oAuth2Credentials.authenticate(authorizationCode, httpSession.getAttribute(Server.USER_SESSION_ID).toString());
}
resp.sendRedirect("/");
}
开发者ID:uber,项目名称:rides-java-sdk,代码行数:21,代码来源:OAuth2CallbackServlet.java
示例3: onError
import com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl; //导入依赖的package包/类
@Override
protected void onError(HttpServletRequest req, HttpServletResponse resp, AuthorizationCodeResponseUrl errorResponse) throws ServletException, IOException {
LOG.severe(errorResponse.getError() + ": " + errorResponse.getErrorDescription());
GenericUrl url = new GenericUrl(req.getRequestURL().toString());
url.setRawPath(SessionManager.SIGN_IN_URL);
resp.sendRedirect(url.build());
}
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:8,代码来源:GoogleAuthenticationCallbackServlet.java
示例4: getUserFromUrl
import com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl; //导入依赖的package包/类
private String getUserFromUrl(AuthorizationCodeResponseUrl authorizationCodeResponseUrl)
throws IOException {
String state = authorizationCodeResponseUrl.getState();
if (!(state == null || state.isEmpty())) {
String decoded = URLDecoder.decode(state, "UTF-8");
String[] items = decoded.split("&");
for (String str : items) {
if (str.startsWith("userId=")) {
return str.substring(7, str.length());
}
}
}
return null;
}
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:OAuthAuthenticator.java
示例5: onError
import com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl; //导入依赖的package包/类
@Override
protected void onError(HttpServletRequest request, HttpServletResponse response,
AuthorizationCodeResponseUrl errorResponse) {
try {
response.sendRedirect("/denied");
} catch (IOException e) {
LOG.warning("Cannot redirect on authorization error.");
}
}
开发者ID:googleads,项目名称:googleads-dfp-java-dfp-playground,代码行数:10,代码来源:OAuth2CallbackServlet.java
示例6: onError
import com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl; //导入依赖的package包/类
@Override
protected void onError(
HttpServletRequest req, HttpServletResponse resp, AuthorizationCodeResponseUrl errorResponse)
throws ServletException, IOException {
resp.sendRedirect("/unauthorized.html");
}
开发者ID:MailFred,项目名称:mailfred-appengine,代码行数:7,代码来源:OAuth2CallbackServlet.java
示例7: callback
import com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl; //导入依赖的package包/类
/**
* Process callback request.
*
* @param requestUrl request URI. URI should contain authorization code generated by authorization
* server
* @param scopes specify exactly what type of access needed. This list must be exactly the same as
* list passed to the method {@link #getAuthenticateUrl(URL, java.util.List)}
* @return id of authenticated user
* @throws OAuthAuthenticationException if authentication failed or <code>requestUrl</code> does
* not contain required parameters, e.g. 'code'
*/
public String callback(URL requestUrl, List<String> scopes) throws OAuthAuthenticationException {
if (!isConfigured()) {
throw new OAuthAuthenticationException("Authenticator is not configured");
}
AuthorizationCodeResponseUrl authorizationCodeResponseUrl =
new AuthorizationCodeResponseUrl(requestUrl.toString());
final String error = authorizationCodeResponseUrl.getError();
if (error != null) {
throw new OAuthAuthenticationException("Authentication failed: " + error);
}
final String code = authorizationCodeResponseUrl.getCode();
if (code == null) {
throw new OAuthAuthenticationException("Missing authorization code. ");
}
try {
TokenResponse tokenResponse =
flow.newTokenRequest(code)
.setRequestInitializer(
request -> {
if (request.getParser() == null) {
request.setParser(flow.getJsonFactory().createJsonObjectParser());
}
request.getHeaders().setAccept(MediaType.APPLICATION_JSON);
})
.setRedirectUri(findRedirectUrl(requestUrl))
.setScopes(scopes)
.execute();
String userId = getUserFromUrl(authorizationCodeResponseUrl);
if (userId == null) {
userId =
getUser(newDto(OAuthToken.class).withToken(tokenResponse.getAccessToken())).getId();
}
flow.createAndStoreCredential(tokenResponse, userId);
return userId;
} catch (IOException ioe) {
throw new OAuthAuthenticationException(ioe.getMessage());
}
}
开发者ID:eclipse,项目名称:che,代码行数:52,代码来源:OAuthAuthenticator.java
示例8: onError
import com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl; //导入依赖的package包/类
@Override
protected void onError(HttpServletRequest req, HttpServletResponse resp,
AuthorizationCodeResponseUrl errorResponse)
throws ServletException, IOException {
// handle error
}
开发者ID:aleksz,项目名称:driveddoc,代码行数:7,代码来源:AuthorizationCallbackServlet.java
示例9: run
import com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl; //导入依赖的package包/类
@Override
public Navigation run() throws Exception {
StringBuffer requestURL = request.getRequestURL();
if(request.getQueryString() != null) {
requestURL.append("?").append(request.getQueryString());
}
AuthorizationCodeResponseUrl responseUrl = new AuthorizationCodeResponseUrl(requestURL.toString());
String code = responseUrl.getCode();
if(responseUrl.getError() != null) {
logger.severe(responseUrl.getError());
return null;
}
if (code == null) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return null;
}
GoogleAuthorizationCodeFlow flow = FusionService.newFlow();
String redirectUri = FusionService.getRedirectUri(request);
GoogleTokenResponse res = flow.newTokenRequest(code).setRedirectUri(redirectUri).execute();
flow.createAndStoreCredential(res, FusionService.getUserId());
logger.fine("success");
return null;
}
开发者ID:soundTricker,项目名称:gas-library-box-server,代码行数:37,代码来源:Oauth2callbackController.java
注:本文中的com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论