Skip to content

JavaWebStack/passport

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation



JWS-Passport

GitHub Workflow Status (branch) GitHub Lines of code Discord Twitter Follow

Introduction

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

Example usage

import org.javawebstack.passport.services.oauth2.InteraAppsOAuth2Service;

class MyApp {
    /* ... */
    protected void setup() {
        HTTPServer httpServer = new HTTPServer().port(1234);

        Passport passport = new Passport("/auth");
        OAuth2Strategy oAuth2Strategy = new OAuth2Strategy("http://localhost:1234");
        oAuth2Strategy.setHttpCallbackHandler((e, callback) -> {
            return "Hello " + callback.getProfile().getName();
        });

        oAuth2Strategy.use("interaapps", new InteraAppsOAuth2Provider("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 
    public void oAuthWithoutHTTPServer() {
        OAuth2Strategy oAuth2Strategy = new OAuth2Strategy("http://localhost:1234");
        oAuth2Strategy.use("interaapps", new InteraAppsOAuth2Provider("myid", "mysecret").setScopes("user:read"));

        // Redirect
        String callbackUrl = ".../callback";
        String redirectUrl = oAuth2Strategy.get("interaapps").redirect(callbackUrl);
        
        // On callback
        OAuth2Callback callback = oAuth2Strategy.get("interaapps").callback(new AbstractObject().set("code", code), callbackUrl);
        System.out.println("Hello "+callback.getProfile().name);
    }

    /* ... */
}

Dependency

<dependency>
    <groupId>org.javawebstack</groupId>
    <artifactId>Passport</artifactId>
    <version>1.0-SNAPSHOT<!-- VERSION --></version>
</dependency>

Services

Service Class Control-Panel More Information
Github GithubOAuth2Service Github Developer Center -
Google GoogleOAuth2Service Google Developer Console -
Discord DiscordOAuth2Service Discord Developer Portal -
Facebook FacebookOAuth2Service Facebook Developer Center TODO
InteraApps InteraAppsOAuth2Service IA-Accounts Developer Center -
Twitch TwitchOAuth2Service Twitch Developers Implements the OAuth authorization code flow

About

Adds authentication with ease to your web application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages