Coder Social home page Coder Social logo

keycloak-capacitor's Introduction

keycloak-capacitor

This is an extended version of the existing keycloak.js Adapter. It's the same code, I try to keep it up-to-date. The version of keyloak and this package match. The only difference are 2 more adapters for capacitor. It's possible to provide custom adapters, but the original library implements a lot of private methods, which are not accessible with custom adapters. Therefore, duplicate implementations are required for custom adapters.

There is an open discussion about implementing the capacitor adapter in the original library here: keycloak/keycloak#10174

Original (v19.0.1) Implementation:

Official Documentation:

Extensions:

  • Added capacitor adapter
  • Added capacitor-native adapter

Adapter: capacitor-native

Adapter to use the system browser.

Prerequisites

  • Setup your iOS App to work with universal links (see official docs linked above)
  • Setup your Android App to work with deep links

The adapter will directly access Capacitors app api to listen to iOS (universal links) and Android deep links. Also the native browser will be opened for the login/logout/register and account management pages.

Usage

  1. Install package
npm i keycloak-capacitor
  1. Use it
public keycloak: Keycloak.KeycloakInstance;

constructor()
{

    this.keycloak = Keycloak({
        clientId: 'webapp',
        realm: 'master',
        url: 'http://localhost:8080/auth/'
    });
    this.keycloak.init({
        adapter: 'capacitor-native',
        responseMode: 'query',
        redirectUri: 'http://localhost:8100'
    });

    // Test if it works, when coming back from this.keycloak.login();
    this.keycloak.onAuthSuccess = () => {
        console.log('authenticated!');
    };

}

Adapter: capacitor

Adapter to use an inApp browser

Prerequisites

  • Install cordova-plugin-browsertab
  • Setup your iOS App to work with universal links (see official docs linked above)
  • Setup your Android App to work with deep links

The adapter will directly access Capacitors app api to listen to iOS (universal links) and Android deep links. Also the inApp browser will be opened for the login/logout/register and account management pages.

Usage

  1. Install package
npm i keycloak-capacitor
  1. Use it

Check out the examples folder.

public keycloak: Keycloak.KeycloakInstance;

constructor()
{

    this.keycloak = Keycloak({
        clientId: 'webapp',
        realm: 'master',
        url: 'http://localhost:8080/auth/'
    });
    this.keycloak.init({
        adapter: 'capacitor',
        responseMode: 'query',
        redirectUri: 'http://localhost:8100'
    });

    // Test if it works, when coming back from this.keycloak.login();
    this.keycloak.onAuthSuccess = () => {
        console.log('authenticated!');
    };

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.