Oauth1aHelper.java
4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.http.HttpServletRequest
* javax.servlet.http.HttpServletResponse
* org.scribe.model.Token
* org.scribe.model.Verifier
* org.scribe.oauth.OAuthService
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.auth.oauth.impl.oauth1a;
import com.adobe.granite.auth.oauth.Provider;
import com.adobe.granite.auth.oauth.impl.helper.OAuthHelper;
import com.adobe.granite.auth.oauth.impl.helper.OAuthToken;
import com.adobe.granite.auth.oauth.impl.helper.OAuthUser;
import com.adobe.granite.auth.oauth.impl.helper.OauthTokenManager;
import com.adobe.granite.auth.oauth.impl.helper.ProviderConfig;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.scribe.model.Token;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Oauth1aHelper
extends OAuthHelper {
private final Logger log;
public Oauth1aHelper(ProviderConfig config) {
super(config);
this.log = LoggerFactory.getLogger(this.getClass());
}
public void requestAuthorization(Provider provider, HttpServletRequest request, HttpServletResponse response, String state, boolean isAuthentication) throws IOException {
try {
OAuthService service = this.getService(provider, request, isAuthentication, this.config.getPersistRequestParamsCallbackUrl());
Token requestToken = service.getRequestToken();
String redirectUrl = service.getAuthorizationUrl(requestToken);
OAuthToken token = this.config.getOAuthTokenManager().getToken(this.config.getClientId(), request);
if (token == null || !token.isAuthentic()) {
token = new OAuthToken(this.config.getClientId(), requestToken.getToken(), requestToken.getSecret(), 1);
} else {
OAuthToken newToken = new OAuthToken(this.config.getClientId(), requestToken.getToken(), requestToken.getSecret(), 3);
if (token.getAttributes() != null) {
for (Map.Entry<String, Object> attr : token.getAttributes().entrySet()) {
newToken.setAttribute(attr.getKey(), attr.getValue());
}
}
token = newToken;
}
if (state != null && state.length() > 0) {
token.setAttribute("state", state);
}
request.setAttribute(this.config.getClientId(), (Object)token);
this.config.getOAuthTokenManager().saveToken(token, request, response);
response.sendRedirect(redirectUrl);
}
catch (Exception e) {
IOException ex = new IOException("Failed requesting authorization");
ex.initCause(e);
throw ex;
}
}
public OAuthUser requestAccessCode(Provider provider, HttpServletRequest request, HttpServletResponse response, boolean isAuthentication, boolean includeExtendedData) throws IOException {
try {
OAuthToken token = this.config.getOAuthTokenManager().getToken(this.config.getClientId(), request);
if (token != null && (token.isAuthentic() || token.getState() == 1)) {
Token requestToken = new Token(token.getKey(), token.getSecret());
String oauthVerifier = request.getParameter("oauth_verifier");
Verifier verifier = new Verifier(oauthVerifier);
Token accessToken = this.getService(provider, request, isAuthentication, this.config.getPersistRequestParamsCallbackUrl()).getAccessToken(requestToken, verifier);
token = new OAuthToken(this.config.getClientId(), accessToken.getToken(), accessToken.getSecret(), 3);
request.setAttribute(this.config.getClientId(), (Object)token);
this.config.getOAuthTokenManager().saveToken(token, request, response);
return this.getUserDetails(provider, request, includeExtendedData);
}
this.log.warn("token was null or not in UNAUTHORIZED state:{}", (Object)(token == null ? null : Integer.valueOf(token.getState())));
return null;
}
catch (Exception e) {
IOException ex = new IOException("Failed requesting access code");
ex.initCause(e);
throw ex;
}
}
}