Passport is a JWS-Module which allows you to create easily Authentication in your WebApp. The OAuth2 Support gives you a unified way of implementing OAuth2-Authorization in your WebApp
classMyApp {
/* ... */protectedvoidsetup() {
HTTPServerhttpServer = newHTTPServer().port(1234);
Passportpassport = newPassport("/auth");
OAuth2StrategyoAuth2Strategy = newOAuth2Strategy("http://localhost:1234");
oAuth2Strategy.setHttpCallbackHandler((e, callback, name) -> {
return"Hello " + callback.getProfile().getName();
});
oAuth2Strategy.use("google", newGoogleOAuth2Provider("myid", "mysecret").setScopes("https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email"));
oAuth2Strategy.use("interaapps", newInteraAppsOAuth2Provider("myid", "mysecret").setScopes("user:read"));
passport.use("oauth2", oAuth2Strategy);
passport.createRoutes(httpServer);
httpServer.start();
// Creates Routes: /auth/oauth2/interaapps, /auth/oauth2/interaapps/callback
}
// JWS-Passport ships also an abstracted form of handling oauth2 publicvoidoAuthWithoutHTTPServer() {
OAuth2StrategyoAuth2Strategy = newOAuth2Strategy("http://localhost:1234");
oAuth2Strategy.use("interaapps", newInteraAppsOAuth2Provider("myid", "mysecret").setScopes("user:read"));
// RedirectStringcallbackUrl = ".../callback";
StringredirectUrl = oAuth2Strategy.get("interaapps").redirect(callbackUrl);
// On callbackOAuth2Callbackcallback = oAuth2Strategy.get("interaapps").callback(newAbstractObject().set("code", code), callbackUrl);
System.out.println("Hello " + callback.getProfile().name);
}
/* ... */
}<dependency>
<groupId>org.javawebstack</groupId>
<artifactId>Passport</artifactId>
<version>1.0-SNAPSHOT<!-- VERSION --></version>
</dependency>| Service | Class | Control-Panel | More Information |
|---|---|---|---|
| Github | GithubOAuth2Provider | Github Developer Center | - |
| GoogleOAuth2Provider | Google Developer Console | - | |
| Discord | DiscordOAuth2Provider | Discord Developer Portal | - |
| FacebookOAuth2Provider | Facebook Developer Center | TODO | |
| InteraApps | InteraAppsOAuth2Provider | IA-Accounts Developer Center | - |
| Twitch | TwitchOAuth2Provider | Twitch Developers | Implements the OAuth authorization code flow |