npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@future-grid/fgp-auth

v19.10.1

Published

fgp-auth is a token based auth lib and base on "auth0 and keycloak.

Downloads

131

Readme

future-grid/fgp-auth

fgp-auth bases on keycloak & auth0 libs, uses typescript as dev language. It is the easy way to integrate token based auth.

Getting Started

install package via npm

npm install --save @future-grid/fgp-auth

keycloak

Add keycloak js file into "index.html". This js comes from keycloak http server.

http(s)://<domain>/auth/js/keycloak.js

Installing(React)

A step by step series of examples that tell you how to get a fgp-auth working with keycloak and react ui project

  • create keycloak config json and import it into App.js(the root component)
{
        "realm": "fgp-ue",  // realm name in cloak
        "auth-server-url": "http://10.153.154.40:32405/auth",  // auth server. replace with keycloak dns
        "ssl-required": "external",
        "redirect_uri": 'http://localhost:3000',       // redirect url. replace with ui dns
        "resource": "ue-ui",
        "credentials": {
          "secret": "35570e3c-54d0-44d1-936b-ea681bc4f5a9" // secret in cloak 
        },
        "confidential-port": 0,
        "clientId": "ue-ui"   // client id in keycloak
      }

then import it into root component(App.js)

import AuthConfig from './configs/authConfig.json';
  • create success and failed callback
/**
* after login successful fgp-auth will call this method to send token back.
**/
const successCallback = (token, operator) => {
         
        localStorage.setItem("accessToken", token);
        operator.getUserInfo().success((info) => {
          this.setState({
            auth: {
              "accessToken": token,
              "op": operator,
              "user": info
            }
          });
          
        }).error(() => {
          // redirect to login page
          this.state.auth.op.logout();
        });

        this.setState({
            auth: true
        })
      };
/**
* error then logout
**/
const errorCallback = () => {
        // when error happened, that's mean auth failed!
        this.state.auth.op.logout();
      };
  • create auth operator instancer
// AuthConfig imported from a json file or just replace this var with a json object
const auth = new AuthFactory(Auths.KC, new AuthProps('fgp-auth-kc', AuthConfig, callbackFnc, errorCallback))

// call getAuth()  send auth request to keycloak server

auth.getAuth()

After login successful keycloak will send a token back then you need to add authorization header of all your ajax requests.
ex. interceptor

componentWillMount(){
        axios.interceptors.request.use(
            config => {
              if (!config.headers.Authorization) {
                const token = localStorage.getItem("accessToken");
                if (token) {
                  config.headers.Authorization = `Bearer ${token}`;
                }
              }
              return config;
            },
            error => Promise.reject(error)
          );
    }

Secured API (optional)

security fgp api server with parameters

  • auth_type: open_id
  • secret: get it from keycloak
  • appid: <client_id> get if from keycloak
  • trusted_issuer: https:///auth/realms/

Built With

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Eric Wang - Initial work & Development

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details