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

@wmiklasewicz/cypress-keycloak

v1.0.4

Published

Cypress commands for Keycloak using the latest Cypress

Downloads

2

Readme

cypress-keycloak

Cypress commands for Keycloak


This package/repository is created based on the fork from https://github.com/babangsund/cypress-keycloak it contains now support for the latest Cypress versions.

Installation

Using npm:

$ npm install cypress-keycloak -D

Using yarn:

$ yarn add cypress-keycloak -D

Then with a module bundler like webpack, add the following line to cypress/support/commands.js | .ts:

// Using ES6
import 'cypress-keycloak';
// using CommonJS
require('cypress-keycloak');

Usage

Two cy commands have been added:

  • cy.logout({ ... }):
    • root: string
    • realm: string
    • redirect_uri?: string, for Keycloak >= 18.0.0 use post_logout_redirect_uri instead
    • post_logout_redirect_uri?: string, for Keycloak < 18.0.0 use post_logout_redirect_uri instead
    • id_token_hint?: string
    • path_prefix?: string = "auth"
  • cy.login({ ... }):
    • root: string
    • realm: string
    • username: string
    • password: string
    • client_id: string
    • redirect_uri: string
    • path_prefix?: string = "auth"
  • cy.loginOTP({ ... }):
    • root: string
    • realm: string
    • username: string
    • password: string
    • client_id: string
    • redirect_uri: string
    • path_prefix?: string = "auth"
    • otp_secret: string
    • otp_credential_id?: string | null = null

Installation:

If you don't want to use login with OTPs you can skip this section.

For generation of OTPs you need to create a new task named generateOTP in your cypress/plugins/index.js | .ts, like discribed in README of Cypress OTP.

To get your OTP secret you need to use e.g. an App for configurating OTP which can display the secret like FreeOTP+. The OTP credential ID can be found in Keycloaks Account Management Console, but only if there are at least two Authenticators configurated. It is only needed for login if you have more than one Authenticator.

Another way is to get these two values is by using the endpoint GET /{realmName}/users/{userId}/credentials.

It is highly recommended to save your username, password, otp_secret and otp_credential_id in .env.*.local or another file within your gitignore.

Example:

describe('thing', () => {
  beforeEach(() => {
    cy.login({
      root: 'https://keycloak.babangsund.com',
      realm: 'stage',
      username: 'babangsund',
      password: 'bacon',
      client_id: 'frontend',
      redirect_uri: 'https://babangsund.com/',
    });

    // or login with OTP
    cy.loginOTP({
      root: 'https://keycloak.babangsund.com',
      realm: 'stage',
      username: 'babangsund',
      password: 'bacon',
      client_id: 'frontend',
      redirect_uri: 'https://babangsund.com/',
      otp_secret: 'OZLDC2HZKM3QUC...', // e.g. 32 chars
      otp_credential_id: '5e231f20-8ca7-35e1-20a694b60181ca9', // e.g. 36 chars
    });
  });

  afterEach(() => {
    cy.logout({
      root: 'https://keycloak.babangsund.com',
      realm: 'stage',
      // using Keycloak < 18.0.0:
      // redirect_uri: 'https://babangsund.com/',
      // using Keycloak >= 18.0.0:
      post_logout_redirect_uri: 'https://babangsund.com/',
    });
  });
});

In case you want to declare these commands only one time with the values it is possible to overwrite them in your cypress/support/commands.js | .ts like this:

Cypress.Commands.overwrite('login', (originalFn) => {
  originalFn({
    root: 'https://keycloak.babangsund.com',
    realm: 'stage',
    username: 'babangsund',
    password: 'bacon',
    client_id: 'frontend',
    redirect_uri: 'https://babangsund.com/',
  })
})

...

And use them like this:

describe('thing', () => {
  beforeEach(() => {
    cy.login();

    // or login with OTP
    cy.loginOTP();
  });

  afterEach(() => {
    cy.logout();
  });
});