本文整理汇总了Java中io.vertx.ext.auth.oauth2.OAuth2Auth.create方法的典型用法代码示例。如果您正苦于以下问题:Java OAuth2Auth.create方法的具体用法?Java OAuth2Auth.create怎么用?Java OAuth2Auth.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.auth.oauth2.OAuth2Auth
的用法示例。
在下文中一共展示了OAuth2Auth.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retrieve
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
@Override
protected OAuth2Auth retrieve() {
JsonObject authConfig = record().getMetadata().copy().mergeIn(record().getLocation());
if (config != null) {
authConfig.mergeIn(config);
}
OAuth2FlowType flow = OAuth2FlowType.valueOf(authConfig.getString("flow.type", "AUTH_CODE").toUpperCase());
if (authConfig.getBoolean("type.keycloak")) {
return OAuth2Auth.createKeycloak(vertx, flow, authConfig);
} else {
return OAuth2Auth.create(vertx, flow, new OAuth2ClientOptions(authConfig));
}
}
示例2: create
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
/**
* Create a OAuth2Auth provider for Google Service Account (Server to Server)
*
* @param serviceAccountJson the configuration json file from your Google API page
* @param httpClientOptions custom http client options
*/
static OAuth2Auth create(Vertx vertx, JsonObject serviceAccountJson, HttpClientOptions httpClientOptions) {
final StringBuilder privateKey = new StringBuilder();
for (String s : serviceAccountJson.getString("private_key").split("\n")) {
if ("-----BEGIN PRIVATE KEY-----".equals(s) || "-----END PRIVATE KEY-----".equals(s)) {
continue;
}
privateKey.append(s);
}
return
OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_JWT, new OAuth2ClientOptions(httpClientOptions)
.setSite("https://accounts.google.com")
.setTokenPath(serviceAccountJson.getString("token_uri"))
.addPubSecKey(new PubSecKeyOptions()
.setAlgorithm("RS256")
.setSecretKey(privateKey.toString()))
.setJWTToken(true)
.setJWTOptions(new JWTOptions()
.setAlgorithm("RS256")
.setExpiresInMinutes(60)
.addAudience("https://www.googleapis.com/oauth2/v4/token")
.setIssuer(serviceAccountJson.getString("client_email"))));
}
示例3: testClientCredentialsMode
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
public void testClientCredentialsMode() {
Vertx vertx = Vertx.vertx();
OAuth2ClientOptions credentials = new OAuth2ClientOptions()
.setClientID("myClientId")
.setClientSecret("myClientSecret")
.setSite("http://localhost:8080");
// Initialize the OAuth2 Library
OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.CLIENT, credentials);
JsonObject tokenConfig = new JsonObject();
// Callbacks
// Save the access token
oauth2.getToken(tokenConfig, res -> {
if (res.failed()) {
System.err.println("Access Token Error: " + res.cause().getMessage());
} else {
// Get the access token object (the authorization code is given from the previous step).
AccessToken token = res.result();
System.out.println("Credentials Mode Get Token Info= " + token.principal().toString());
oauth2.api(HttpMethod.GET, "/secure", new JsonObject().put("access_token", token.principal().getString("access_token")), res2 -> {
// the user object should be returned here...
System.out.println("Secure Info= " + res2.result().toString());
});
}
});
}
示例4: testPasswordMode
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
public void testPasswordMode() {
Vertx vertx = Vertx.vertx();
OAuth2ClientOptions credentials = new OAuth2ClientOptions()
.setClientID("myClientId")
.setClientSecret("myClientSecret")
.setSite("http://localhost:8080");
OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.PASSWORD, credentials);
JsonObject tokenConfig = new JsonObject()
.put("username", "admin")
.put("password", "admin");
// Callbacks
// Save the access token
oauth2.getToken(tokenConfig, res -> {
if (res.failed()) {
System.err.println("Access Token Error: " + res.cause().getMessage());
} else {
// Get the access token object (the authorization code is given from the previous step).
AccessToken token = res.result();
System.out.println("Password Mode Get Token Info= " + token.principal().toString());
oauth2.api(HttpMethod.GET, "/verifyToken", new JsonObject().put("access_token", token.principal().getString("access_token")), res2 -> {
// the user object should be returned here...
System.out.println("verifyToken Info= " + res2.result().toString());
//刷新token
if (token.expired()) {
// Callbacks
token.refresh(res3 -> {
if (res3.succeeded()) {
// /System.out.println("Refresh Token success= " + res3.result().toString());
} else {
//System.out.println("Refresh Token fail= " + res3.result().toString());
}
});
}
});
}
});
}
示例5: example59
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
public void example59(Vertx vertx, Router router) {
// create an OAuth2 provider, clientID and clientSecret should be requested to Google
OAuth2Auth authProvider = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions()
.setClientID("CLIENT_ID")
.setClientSecret("CLIENT_SECRET")
.setSite("https://accounts.google.com")
.setTokenPath("https://www.googleapis.com/oauth2/v3/token")
.setAuthorizationPath("/o/oauth2/auth"));
// create a oauth2 handler on our domain: "http://localhost:8080"
OAuth2AuthHandler oauth2 = OAuth2AuthHandler.create(authProvider, "http://localhost:8080");
// these are the scopes
oauth2.addAuthority("profile");
// setup the callback handler for receiving the Google callback
oauth2.setupCallback(router.get("/callback"));
// protect everything under /protected
router.route("/protected/*").handler(oauth2);
// mount some handler under the protected zone
router.route("/protected/somepage").handler(rc -> rc.response().end("Welcome to the protected resource!"));
// welcome page
router.get("/").handler(ctx -> ctx.response().putHeader("content-type", "text/html").end("Hello<br><a href=\"/protected/somepage\">Protected by Google</a>"));
}
示例6: setUp
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions()
.setClientID("client-id")
.setClientSecret("client-secret")
.setSite("http://localhost:8080"));
final CountDownLatch latch = new CountDownLatch(1);
server = vertx.createHttpServer().requestHandler(req -> {
if (req.method() == HttpMethod.POST && "/oauth/token".equals(req.path())) {
req.setExpectMultipart(true).bodyHandler(buffer -> {
try {
assertEquals(config, queryToJSON(buffer.toString()));
} catch (UnsupportedEncodingException e) {
fail(e);
}
req.response().setStatusCode(code).end();
});
} else {
req.response().setStatusCode(400).end();
}
}).listen(8080, ready -> {
if (ready.failed()) {
throw new RuntimeException(ready.cause());
}
// ready
latch.countDown();
});
latch.await();
}
示例7: create
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
/**
* Create a OAuth2Auth provider for Heroku
*
* @param clientId the client id given to you by Heroku
* @param clientSecret the client secret given to you by Heroku
* @param httpClientOptions custom http client options
*/
static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, HttpClientOptions httpClientOptions) {
return
OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions(httpClientOptions)
.setSite("https://id.heroku.com")
.setTokenPath("/oauth/token")
.setAuthorizationPath("/oauth/authorize")
.setScopeSeparator(" ")
.setClientID(clientId)
.setClientSecret(clientSecret));
}
示例8: create
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
/**
* Create a OAuth2Auth provider for LinkedIn
*
* @param clientId the client id given to you by LinkedIn
* @param clientSecret the client secret given to you by LinkedIn
* @param httpClientOptions custom http client options
*/
static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, HttpClientOptions httpClientOptions) {
return
OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions(httpClientOptions)
.setSite("https://www.linkedin.com")
.setTokenPath("/uas/oauth2/accessToken")
.setAuthorizationPath("/uas/oauth2/authorization")
.setUserInfoPath("/people/~")
.setScopeSeparator(" ")
.setClientID(clientId)
.setClientSecret(clientSecret));
}
示例9: create
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
/**
* Create a OAuth2Auth provider for CloudFoundry UAA
*
* @param clientId the client id given to you by CloudFoundry UAA
* @param clientSecret the client secret given to you by CloudFoundry UAA
* @param uuaURL the url to your UUA server instance
* @param httpClientOptions custom http client options
*/
static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, String uuaURL, HttpClientOptions httpClientOptions) {
return
OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions(httpClientOptions)
.setSite(uuaURL)
.setTokenPath("/oauth/token")
.setAuthorizationPath("/oauth/authorize")
.setScopeSeparator(" ")
.setClientID(clientId)
.setClientSecret(clientSecret));
}
示例10: create
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
/**
* Create a OAuth2Auth provider for SoundCloud
*
* @param clientId the client id given to you by SoundCloud
* @param clientSecret the client secret given to you by SoundCloud
* @param httpClientOptions custom http client options
*/
static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, HttpClientOptions httpClientOptions) {
return
OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions(httpClientOptions)
.setSite("https://api.soundcloud.com")
.setTokenPath("/oauth2/token")
.setAuthorizationPath("/connect")
.setUserInfoPath("/me.json")
.setClientID(clientId)
.setClientSecret(clientSecret));
}
示例11: create
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
/**
* Create a OAuth2Auth provider for Facebook
*
* @param clientId the client id given to you by Facebook
* @param clientSecret the client secret given to you by Facebook
* @param httpClientOptions custom http client options
*/
static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, HttpClientOptions httpClientOptions) {
return
OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions(httpClientOptions)
.setSite("https://www.facebook.com")
.setTokenPath("https://graph.facebook.com/oauth/access_token")
.setAuthorizationPath("/dialog/oauth")
.setUserInfoPath("https://graph.facebook.com/me")
.setScopeSeparator(",")
.setClientID(clientId)
.setClientSecret(clientSecret));
}
示例12: create
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
/**
* Create a OAuth2Auth provider for Twitter
*
* @param clientId the client id given to you by Twitter
* @param clientSecret the client secret given to you by Twitter
* @param httpClientOptions custom http client options
*/
static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, HttpClientOptions httpClientOptions) {
return
OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions(httpClientOptions)
.setSite("https://api.twitter.com")
.setTokenPath("/oauth/access_token")
.setAuthorizationPath("/oauth/authorize")
.setUserInfoPath("/1.1/users/show.json")
.setClientID(clientId)
.setClientSecret(clientSecret));
}
示例13: setUp
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, oauthConfig);
final CountDownLatch latch = new CountDownLatch(1);
server = vertx.createHttpServer().requestHandler(req -> {
if (req.method() == HttpMethod.GET && "/oauth/userinfo".equals(req.path())) {
assertTrue(req.getHeader("Authorization").contains("Bearer "));
try {
assertEquals(googleParams, queryToJSON(req.query()));
} catch (UnsupportedEncodingException e) {
fail(e);
}
req.response().putHeader("Content-Type", "application/json").end(fixture.encode());
} else {
req.response().setStatusCode(400).end();
}
}).listen(8080, ready -> {
if (ready.failed()) {
throw new RuntimeException(ready.cause());
}
// ready
latch.countDown();
});
latch.await();
}
示例14: create
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
/**
* Create a OAuth2Auth provider for live.com
*
* @param clientId the client id given to you by live.com
* @param clientSecret the client secret given to you by live.com
* @param httpClientOptions custom http client options
*/
static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, HttpClientOptions httpClientOptions) {
return
OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions(httpClientOptions)
.setSite("https://login.live.com")
.setTokenPath("/oauth20_token.srf")
.setAuthorizationPath("/oauth20_authorize.srf")
.setScopeSeparator(" ")
.setClientID(clientId)
.setClientSecret(clientSecret));
}
示例15: setUp
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions()
.setClientID("client-id")
.setClientSecret("client-secret")
.setSite("http://localhost:8080"));
final CountDownLatch latch = new CountDownLatch(1);
server = vertx.createHttpServer().requestHandler(req -> {
if (req.method() == HttpMethod.POST && "/oauth/token".equals(req.path())) {
req.setExpectMultipart(true).bodyHandler(buffer -> {
try {
assertEquals(config, queryToJSON(buffer.toString()));
} catch (UnsupportedEncodingException e) {
fail(e);
}
req.response().putHeader("Content-Type", "application/json").end(fixture.encode());
});
} else {
req.response().setStatusCode(400).end();
}
}).listen(8080, ready -> {
if (ready.failed()) {
throw new RuntimeException(ready.cause());
}
// ready
latch.countDown();
});
latch.await();
}