本文整理汇总了Java中io.vertx.ext.auth.oauth2.OAuth2Auth类的典型用法代码示例。如果您正苦于以下问题:Java OAuth2Auth类的具体用法?Java OAuth2Auth怎么用?Java OAuth2Auth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OAuth2Auth类属于io.vertx.ext.auth.oauth2包,在下文中一共展示了OAuth2Auth类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: create
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
/**
* Create a OAuth2Auth provider for Microsoft Azure Active Directory
*
* @param clientId the client id given to you by Azure
* @param clientSecret the client secret given to you by Azure
* @param guid the guid of your application given to you by Azure
* @param httpClientOptions custom http client options
*/
static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, String guid, HttpClientOptions httpClientOptions) {
return
OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions(httpClientOptions)
.setSite("https://login.windows.net/" + guid)
.setTokenPath("/oauth2/token")
.setAuthorizationPath("/oauth2/authorize")
.setScopeSeparator(",")
.setClientID(clientId)
.setClientSecret(clientSecret)
.setExtraParameters(
new JsonObject().put("resource", guid)));
}
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:21,代码来源:AzureADAuth.java
示例2: 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));
}
}
开发者ID:pflima92,项目名称:jspare-vertx-ms-blueprint,代码行数:17,代码来源:OAuth2ServiceImpl.java
示例3: authCallback
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
private void authCallback(OAuth2Auth oauth2, String hostURL, RoutingContext context) {
final String code = context.request().getParam("code");
// code is a require value
if (code == null) {
context.fail(400);
return;
}
final String redirectTo = context.request().getParam("redirect_uri");
final String redirectURI = hostURL + context.currentRoute().getPath() + "?redirect_uri=" + redirectTo;
oauth2.getToken(new JsonObject().put("code", code).put("redirect_uri", redirectURI), ar -> {
if (ar.failed()) {
logger.warn("Auth fail");
context.fail(ar.cause());
} else {
logger.info("Auth success");
context.setUser(ar.result());
context.response()
.putHeader("Location", redirectTo)
.setStatusCode(302)
.end();
}
});
}
开发者ID:sczyh30,项目名称:vertx-blueprint-microservice,代码行数:24,代码来源:APIGatewayVerticle.java
示例4: customRouteConfiguration
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
@Override
public void customRouteConfiguration(Vertx vertx, Router router, boolean secure, String host, int port) {
final JsonObject config = vertx.getOrCreateContext().config();
final OAuth2Auth authProvider = GithubAuth
.create(vertx,config.getString("clientID"),config.getString("clientSecret"));
// store authentication
router.route().handler(UserSessionHandler.create(authProvider));
final String hostURI = (secure ? "https://" : "http://") + host + ":" + port;
final String callbackURI = hostURI+"/callback";
final OAuth2AuthHandler oauth2 = OAuth2AuthHandler.create(authProvider, callbackURI);
// setup the callback handler for receiving the GitHub callback
oauth2.setupCallback(router.route());
// Serve the static private pages from directory 'private'
router.route("/private/*").handler(oauth2);
router.get("/").handler(ctx ->
ctx.
response().
putHeader("content-type", "text/html").
end("Hello <br><a href=\"/private/\">Protected by Github</a>"));
}
开发者ID:amoAHCP,项目名称:vxms,代码行数:26,代码来源:CustomRouterConfig.java
示例5: example58
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
public void example58(Vertx vertx, Router router) {
// create an OAuth2 provider, clientID and clientSecret should be requested to github
OAuth2Auth authProvider = GithubAuth.create(vertx, "CLIENT_ID", "CLIENT_SECRET");
// create a oauth2 handler on our running server
// the second argument is the full url to the callback as you entered in your provider management console.
OAuth2AuthHandler oauth2 = OAuth2AuthHandler.create(authProvider, "https://myserver.com/callback");
// setup the callback handler for receiving the GitHub callback
oauth2.setupCallback(router.route());
// 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 Github</a>"));
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:21,代码来源:WebExamples.java
示例6: OAuth2AuthHandlerImpl
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
public OAuth2AuthHandlerImpl(OAuth2Auth authProvider, String callbackURL) {
super(verifyProvider(authProvider), Type.BEARER);
try {
if (callbackURL != null) {
final URL url = new URL(callbackURL);
this.host = url.getProtocol() + "://" + url.getHost() + (url.getPort() == -1 ? "" : ":" + url.getPort());
this.callbackPath = url.getPath();
} else {
this.host = null;
this.callbackPath = null;
}
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:17,代码来源:OAuth2AuthHandlerImpl.java
示例7: authURI
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
private String authURI(String redirectURL) {
final JsonObject config = new JsonObject()
.put("state", redirectURL);
if (host != null) {
config.put("redirect_uri", host + callback.getPath());
}
if (extraParams != null) {
config.mergeIn(extraParams);
}
if (scopes.size() > 0) {
JsonArray _scopes = new JsonArray();
// scopes are passed as an array because the auth provider has the knowledge on how to encode them
for (String authority : scopes) {
_scopes.add(authority);
}
config.put("scopes", _scopes);
}
return ((OAuth2Auth) authProvider).authorizeURL(config);
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:25,代码来源:OAuth2AuthHandlerImpl.java
示例8: create
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
/**
* Create a OAuth2Auth provider for Google
*
* @param clientId the client id given to you by Google
* @param clientSecret the client secret given to you by Google
* @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://accounts.google.com")
.setTokenPath("https://www.googleapis.com/oauth2/v3/token")
.setAuthorizationPath("/o/oauth2/auth")
.setIntrospectionPath("https://www.googleapis.com/oauth2/v3/tokeninfo")
.setUserInfoPath("https://www.googleapis.com/oauth2/v3/userinfo")
.setJwkPath("https://www.googleapis.com/oauth2/v3/certs")
.setUserInfoParameters(new JsonObject()
.put("alt", "json"))
.setScopeSeparator(" ")
.setClientID(clientId)
.setClientSecret(clientSecret));
}
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:23,代码来源:GoogleAuth.java
示例9: testLoadJWK2
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
@Test
@Ignore
public void testLoadJWK2() {
JsonObject config = new JsonObject("{\n" +
" \"realm\": \"master\",\n" +
" \"auth-server-url\": \"http://localhost:8080/auth\",\n" +
" \"ssl-required\": \"external\",\n" +
" \"resource\": \"test\",\n" +
" \"credentials\": {\n" +
" \"secret\": \"b0568625-a482-45d8-af8b-27beba502ed3\"\n" +
" }\n" +
"}");
OAuth2Auth oauth2 = KeycloakAuth.create(vertx, config);
oauth2.loadJWK(load -> {
assertFalse(load.failed());
testComplete();
});
await();
}
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:23,代码来源:OAuth2KeyRotationTest.java
示例10: unknownHost
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
@Test
public void unknownHost() {
OAuth2Auth auth = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions()
.setClientID("client-id")
.setClientSecret("client-secret")
.setSite("http://zlouklfoux.net.com.info.pimpo.molo"));
auth.authenticate(tokenConfig, res -> {
if (res.failed()) {
assertThat(res.cause(), instanceOf(UnknownHostException.class));
testComplete();
} else {
fail("Should have failed");
}
});
await();
}
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:17,代码来源:OAuth2FailureTest.java
示例11: 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());
});
}
});
}
开发者ID:openmg,项目名称:metagraph-auth,代码行数:26,代码来源:VertxOAuth2ClientTest.java
示例12: 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());
}
});
}
});
}
});
}
开发者ID:openmg,项目名称:metagraph-auth,代码行数:38,代码来源:VertxOAuth2ClientTest.java
示例13: getOAuth2Provider
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
static void getOAuth2Provider(ServiceDiscovery discovery, JsonObject filter, Handler<AsyncResult<OAuth2Auth>> resultHandler) {
discovery.getRecord(filter, ar -> {
if (ar.failed() || ar.result() == null) {
resultHandler.handle(Future.failedFuture("No matching record"));
} else {
resultHandler.handle(Future.succeededFuture(discovery.getReference(ar.result()).get()));
}
});
}
开发者ID:pflima92,项目名称:jspare-vertx-ms-blueprint,代码行数:10,代码来源:OAuth2Service.java
示例14: 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>"));
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:28,代码来源:WebExamples.java
示例15: verifyProvider
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
/**
* This is a verification step, it can abort the instantiation by
* throwing a RuntimeException
*
* @param provider a auth provider
* @return the provider if valid
*/
private static AuthProvider verifyProvider(AuthProvider provider) {
if (provider instanceof OAuth2Auth) {
if (((OAuth2Auth) provider).getFlowType() != AUTH_CODE) {
throw new IllegalArgumentException("OAuth2Auth + Bearer Auth requires OAuth2 AUTH_CODE flow");
}
}
return provider;
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:17,代码来源:OAuth2AuthHandlerImpl.java
示例16: parseCredentials
import io.vertx.ext.auth.oauth2.OAuth2Auth; //导入依赖的package包/类
@Override
public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) {
parseAuthorization(context, true, parseAuthorization -> {
if (parseAuthorization.failed()) {
handler.handle(Future.failedFuture(parseAuthorization.cause()));
return;
}
// Authorization header could be null as we mark it as optional
final String token = parseAuthorization.result();
if (token == null) {
// redirect request to the oauth2 server as we know nothing about this request
if (callback == null) {
handler.handle(Future.failedFuture("callback route is not configured."));
return;
}
// the redirect is processed as a failure to abort the chain
handler.handle(Future.failedFuture(new HttpStatusException(302, authURI(context.request().uri()))));
} else {
// attempt to decode the token and handle it as a user
((OAuth2Auth) authProvider).decodeToken(token, decodeToken -> {
if (decodeToken.failed()) {
handler.handle(Future.failedFuture(new HttpStatusException(401, decodeToken.cause().getMessage())));
return;
}
context.setUser(decodeToken.result());
// continue
handler.handle(Future.succeededFuture());
});
}
});
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:34,代码来源:OAuth2AuthHandlerImpl.java
示例17: 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));
}
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:18,代码来源:HerokuAuth.java
示例18: 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));
}
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:19,代码来源:LinkedInAuth.java
示例19: 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));
}
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:19,代码来源:CloudFoundryAuth.java
示例20: 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));
}
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:18,代码来源:SoundcloudAuth.java
注:本文中的io.vertx.ext.auth.oauth2.OAuth2Auth类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论