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

tecsinapse-keycloak-js

v2.0.9

Published

Login, logout and refresh token for Keycloak programmatically

Downloads

32

Readme

tecsinapse-keycloak-js

How to use tecsinapse-keycloak-js

Use npm install tecsinapse-keycloak-js --save to add the lib in your project.

Login with tecsinapse-keycloak-js

import TecSinapseKeycloak from 'tecsinapse-keycloak-js;

const options = {
  realm:'your_realm',
  urlServer:'http://yourkeycloakserver.com',
  adminUsername: '[email protected]',
  adminPassword: 'youruseradminpassword'
};

TecSinapseKeycloak.login(email, password, options);
  • Email: email of the user to do login

  • Password: password of the user to do login

  • Options: an object that contains data to configure your access to KeycloakServer. This object contains following attributes:

    • urlServer: The url of the KeycloakServer. Ex.: http://localhost:8081.
    • realm: The realm of your application in the KeycloakServer.
    • clientId: The clientId where you will login.
    • adminUsername: User which contains admin permission in your KeycloakServer to query data user.
    • adminPassword: Password which contains admin permission in your KeycloakServer to query data user.
    • transient(optional): Set this attribute with true, if you don't want save token in the session.
    • daysToExpireCookie(optional): Set this attribute with the number of days to expire the cookie.
    • fetcher(optional): Custom fetch like node-fetch.

This method return a promise which contains the accessToken created by KeycloakServer.

let accessToken = TecSinapseKeycloak.login(email, password, options).then(accessToken => accessToken);

  • Email: Email of user to do login.
  • Password: Password of user to do login.
  • Options: Same of login method.
Logout

This method logout user at KeycloakServer.

TecSinapseKeycloak.logout(options, callback);

  • Options: Same of login method.
  • callback: Callback function. Ex.: redirect to login page.
isLogged

This method return a boolean to verify if your user still logged in

TecSinapseKeycloak.isLogged();

getAccessToken

This method return the accessToken created by KeycloakServer

TecSinapseKeycloak.getAccessToken();

getRefreshToken

This method return the refreshToken created by KeycloakServer

TecSinapseKeycloak.getRefreshToken();

getUser

This method return a promise which contains a JSON object that represents the user at KeycloakServer

TecSinapseKeycloak.getUser(userEmail, options).then(user => user);

  • Options: Same of login method.
  • userEmail: Email to search user at KeycloakServer.
getRoles

This method return a promise which contains an Array of roles user

TecSinapseKeycloak.getRoles(options, userId).then(roles => roles);

  • Options: Same of login method.
  • userId: UserId of user at KeycloakServer.
hasRole

This method return a promise which contains a boolean value

TecSinapseKeycloak.hasRole(options, userId, role);

  • Options: Same of login method.
  • userId: UserId of user at KeycloakServer.
  • role: Role defined at KeycloakServer.
getToken

This method doesn't save token on cookie, it just returns the json object of KeycloakServer

TecSinapseKeycloak.getToken(email, password, options);

  • Email: Email of user to get token.
  • Password: Password of user to get token.
  • Options: Same of login method.

Meteor

Example of use with Meteor without Accounts https://github.com/tecsinapse/tecsinapse-keycloak-meteor-example

Specifically in this file https://github.com/tecsinapse/tecsinapse-keycloak-meteor-example/blob/master/imports/ui/components/info/info.js

Developer

New Release

  • npm run compile
  • npm publish

Questions?