本文整理汇总了Java中com.github.scribejava.core.oauth.OAuth20Service类的典型用法代码示例。如果您正苦于以下问题:Java OAuth20Service类的具体用法?Java OAuth20Service怎么用?Java OAuth20Service使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OAuth20Service类属于com.github.scribejava.core.oauth包,在下文中一共展示了OAuth20Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
public static void main (String[] args) {
ResourceBundle secrets = ResourceBundle.getBundle("facebookutil/secret");
final OAuth20Service service = new ServiceBuilder()
.apiKey(secrets.getString("clientId"))
.apiSecret(secrets.getString("clientSecret"))
.callback("https://duke.edu/")
.grantType("client_credentials")
.build(FacebookApi.instance());
String url = "https://graph.facebook.com/oauth/access_token?";
url = url + "&client_id" + "=" + secrets.getString("clientId");
url = url + "&client_secret" + "=" + secrets.getString("clientSecret");
url = url + "&grant_type" + "=" + "client_credentials";
final OAuthRequest request =
new OAuthRequest(Verb.GET, url, service);
service.signRequest(new OAuth2AccessToken(""), request);
System.out.println(request.getBodyContents());
System.out.println(request.getUrl());
Response response = request.send();
System.out.println(response.getBody());
}
示例2: getAuthURL
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
/**
* @return A string containing a URL that we can send visitors to in order to authenticate them
*/
public String getAuthURL(String originatingURL){
// I think we have to create a new service for every request we send out
// since each one needs a different secretState
final OAuth20Service service = new ServiceBuilder()
.apiKey(clientId)
.apiSecret(clientSecret)
.scope("email") // replace with desired scope
.state(generateSharedGoogleSecret(originatingURL))
.callback(callbackURL)
.build(GoogleApi20.instance());
final Map<String, String> additionalParams = new HashMap<>();
additionalParams.put("access_type", "offline");
additionalParams.put("prompt", "consent");
final String authorizationUrl = service.getAuthorizationUrl(additionalParams);
return authorizationUrl;
}
示例3: validate
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
@Override
public CredentialValidationResult validate(Credential credential) {
if (credential instanceof TokenResponseCredential) {
TokenResponseCredential tokenCredential = (TokenResponseCredential) credential;
OAuthRequest request = new OAuthRequest(Verb.GET, "https://www.googleapis.com/oauth2/v3/userinfo");
OAuth20Service service = tokenCredential.getService();
OAuth2AccessToken token = tokenCredential.getTokenResponse();
service.signRequest(token, request);
try {
Response oResp = service.execute(request);
String body = oResp.getBody();
OAuth2User oAuth2User = jsonProcessor.extractUserInfo(body);
return new CredentialValidationResult(oAuth2User);
} catch (InterruptedException | ExecutionException | IOException e) {
e.printStackTrace(); // FIXME
}
}
return CredentialValidationResult.NOT_VALIDATED_RESULT;
}
示例4: redirect
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
@Override
public CompletableFuture<RedirectAction> redirect(AsyncWebContext context) {
init(context);
final CompletableFuture<OAuth20Service> serviceFuture;
if (this.configuration.isWithState()) {
final String state = getStateParameter();
logger.debug("save sessionState: {}", state);
serviceFuture = context.getSessionStore().set(context, this.configuration.getStateSessionAttributeName(), state)
.thenApply(v -> this.configuration.buildService(context, state));
} else {
serviceFuture = CompletableFuture.completedFuture(this.configuration.getService());
}
return serviceFuture.thenApply(service -> service.getAuthorizationUrl(this.configuration.getCustomParams()))
.thenApply(authUrl -> {
logger.debug("authorizationUrl: {}", authUrl);
return RedirectAction.redirect((String) authUrl);
});
}
示例5: doGet
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String providerName = StringUtils.substringAfterLast(req.getRequestURI(), "/");
LOGGER.info("Authz request for provider: [{}]", providerName);
OAuthProvider provider = this.providerFactory.getProvider(providerName);
LOGGER.info("OAuthProvider: [{}]", provider);
OAuth20Service oauth2Service = this.providerFactory.getOAuth2Service(providerName);
if (oauth2Service == null) {
oauth2Service = new ServiceBuilder().apiKey(provider.getApiKey()).apiSecret(provider.getApiSecret())
.callback(provider.getCallbackURL()).build(provider.getApi());
this.providerFactory.addOAuth2Service(providerName, oauth2Service);
}
String authorizationUrl = oauth2Service.getAuthorizationUrl();
LOGGER.info("Authz URL: [{}]", authorizationUrl);
resp.sendRedirect(authorizationUrl);
}
示例6: processRequest
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
private void processRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String code = req.getParameter("code");
LOGGER.info("OAuth2 code: [{}]", code);
String provider = StringUtils.substringAfterLast(req.getRequestURI(), "/");
LOGGER.info("Provider: [{}]", provider);
OAuth20Service oAuth2Service = this.providerFactory.getOAuth2Service(provider);
OAuth2AccessToken token = null;
try {
token = oAuth2Service.getAccessToken(code);
LOGGER.info("OAuth2AccessToken: [{}]", token);
OAuthRequest oReq = new OAuthRequest(Verb.GET, "https://api.linkedin.com/v1/people/~?format=json");
oAuth2Service.signRequest(token, oReq);
Response oResp = oAuth2Service.execute(oReq);
LOGGER.info("Linkedin Profile: [{}]", oResp.getBody());
resp.getOutputStream().write(oResp.getBody().getBytes(StandardCharsets.UTF_8));
} catch (InterruptedException | ExecutionException ex) {
}
}
示例7: login
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
@RequestMapping("/login")
public OAuthResponse login()
{
UUID uuid = UUID.randomUUID();
State state = new State();
state.setUuid(uuid);
state.setApiVersion(RuneLiteAPI.getVersion());
OAuth20Service service = new ServiceBuilder()
.apiKey(oauthClientId)
.apiSecret(oauthClientSecret)
.scope(SCOPE)
.callback(RL_OAUTH_URL)
.state(gson.toJson(state))
.build(GoogleApi20.instance());
String authorizationUrl = service.getAuthorizationUrl();
OAuthResponse lr = new OAuthResponse();
lr.setOauthUrl(authorizationUrl);
lr.setUid(uuid);
return lr;
}
示例8: getRequestForProvider
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
static public OAuthRequest getRequestForProvider(
final String providerName,
final Verb httpVerb,
final OAuth2AccessToken oa2token,
final URL url,
final HashMap<String,Object> cfg,
@Nullable final ReadableMap params
) {
final OAuth20Service service =
OAuthManagerProviders.getApiFor20Provider(providerName, cfg, null, null);
OAuthConfig config = service.getConfig();
OAuthRequest request = new OAuthRequest(httpVerb, url.toString(), config);
String token = oa2token.getAccessToken();
request = OAuthManagerProviders.addParametersToRequest(request, token, params);
//
Log.d(TAG, "Making request for " + providerName + " to add token " + token);
// Need a way to standardize this, but for now
if (providerName.equalsIgnoreCase("slack")) {
request.addParameter("token", token);
}
return request;
}
示例9: configurableService
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
private static OAuth20Service configurableService(
final HashMap cfg,
@Nullable final ReadableMap opts,
final String callbackUrl
) {
ServiceBuilder builder = OAuthManagerProviders._oauth2ServiceBuilder(cfg, opts, callbackUrl);
Log.d(TAG, "Creating ConfigurableApi");
//Log.d(TAG, " authorize_url: " + cfg.get("authorize_url"));
//Log.d(TAG, " access_token_url: " + cfg.get("access_token_url"));
ConfigurableApi api = ConfigurableApi.instance()
.setAccessTokenEndpoint((String) cfg.get("access_token_url"))
.setAuthorizationBaseUrl((String) cfg.get("authorize_url"));
if (cfg.containsKey("access_token_verb")) {
//Log.d(TAG, " access_token_verb: " + cfg.get("access_token_verb"));
api.setAccessTokenVerb((String) cfg.get("access_token_verb"));
}
return builder.build(api);
}
示例10: OAuthManagerFragmentController
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
public OAuthManagerFragmentController(
final ReactContext mReactContext,
android.app.FragmentManager fragmentManager,
final String providerName,
OAuth20Service oauthService,
final String callbackUrl
) {
this.uiHandler = new Handler(Looper.getMainLooper());
this.fragmentManager = fragmentManager;
this.context = mReactContext;
this.providerName = providerName;
this.authVersion = "2.0";
this.oauth20Service = oauthService;
this.callbackUrl = callbackUrl;
}
示例11: googleLogin
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
public void googleLogin() throws IOException {
String CALL_BACK_URL="http://localhost:8084/loginAndSec/GcallBack";
ExternalContext externalContext = externalContext();
HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
String callBackURL = CALL_BACK_URL;
//System.out.println("google.GoogleLoginServlet.doGet(): callBackURL=" + callBackURL);
//Configure
ServiceBuilder builder = new ServiceBuilder();
OAuth20Service service = builder.apiKey(CLIENT_ID)
.apiSecret(CLIENT_SECRET)
.callback(callBackURL)
.scope("email")
.build(GoogleApi20.instance()); //Now build the call
HttpSession sess = request.getSession();
sess.setAttribute("oauth2Service", service);
String authURL = service.getAuthorizationUrl(null);
//System.out.println("service.getAuthorizationUrl(null)->" + authURL);
externalContext.redirect(authURL);
}
示例12: isOrganizationMember
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
/**
* Check to see that login is a member of organization.
*
* A 204 response code indicates organization membership. 302 and 404 codes are not treated as exceptional,
* they indicate various ways in which a login is not a member of the organization.
*
* @see <a href="https://developer.github.com/v3/orgs/members/#response-if-requester-is-an-organization-member-and-user-is-a-member">GitHub members API</a>
*/
private boolean isOrganizationMember(OAuth2AccessToken accessToken, String organization, String login) throws IOException, ExecutionException, InterruptedException {
String requestUrl = settings.apiURL() + format("orgs/%s/members/%s", organization, login);
OAuth20Service scribe = new ServiceBuilder(settings.clientId())
.apiSecret(settings.clientSecret())
.build(scribeApi);
OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl);
scribe.signRequest(accessToken, request);
Response response = scribe.execute(request);
int code = response.getCode();
switch (code) {
case HttpURLConnection.HTTP_MOVED_TEMP:
case HttpURLConnection.HTTP_NOT_FOUND:
case HttpURLConnection.HTTP_NO_CONTENT:
LOGGER.trace("Orgs response received : {}", code);
return code == HttpURLConnection.HTTP_NO_CONTENT;
default:
throw unexpectedResponseCode(requestUrl, response);
}
}
示例13: storeConnectedAccountId
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
public ConnectResult storeConnectedAccountId(String code, Function<ConfigurationKeys, Configuration.ConfigurationPathKey> keyResolver) {
try {
String connectClientID = configurationManager.getRequiredValue(keyResolver.apply(STRIPE_CONNECT_CLIENT_ID));
String clientSecret = getSystemApiKey();
OAuth20Service service = new ServiceBuilder(connectClientID).apiSecret(clientSecret).build(new StripeConnectApi());
Map<String, String> token = Json.fromJson(service.getAccessToken(code).getRawResponse(), new TypeReference<Map<String, String>>() {});
String accountId = token.get("stripe_user_id");
if(accountId != null) {
configurationManager.saveConfig(keyResolver.apply(ConfigurationKeys.STRIPE_CONNECTED_ID), accountId);
}
return new ConnectResult(accountId, accountId != null, token.get("error_message"));
} catch (Exception e) {
log.error("cannot retrieve account ID", e);
return new ConnectResult(null, false, e.getMessage());
}
}
示例14: processResponse
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
private void processResponse (Response response,
ResourceBundle secrets,
OAuth20Service service) {
LoginObject login = new LoginObject();
login.setUserID(secrets.getString("facebookId"));
login.setToken(new OAuth2AccessToken(ParseHelper.getFirstGroup(TOKEN_REGEX,
response.getBody())));
login.setService(service);
myLoginObject = login;
}
示例15: createService
import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
private OAuth20Service createService (ResourceBundle secrets) {
return new ServiceBuilder()
.apiKey(secrets.getString("facebookId"))
.apiSecret(secrets.getString("facebookSecret"))
.callback(secrets.getString("callback"))
.grantType("client_credentials")
.build(FacebookApi.instance());
}