2.0.1 • Published 8 months ago

cypress-msal-login v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

cypress-msal-login

Cypress command extension to log into a SSO App through the Microsoft Authentication flow using the MSAL library in the app.

Installation

This package depends on the MSAL browser library to be installed in your application (peerDependency)

npm install @azure/msal-browser

Add the cypress package as a dev dependency

npm install --dev cypress-msal-login

## Login with MSAL account

The login command requires three parameters. Here is a minimal example:

cy.msalLogin(
  {
    email: 'my-test-user@cypress.com',
    password: 'whatever'
  },
  {
    auth: {
    clientId: '<application-client-id>',
    authority: 'https://login.microsoftonline.com/<application-tenant-id>',
    },
    cache: {
      cacheLocation: BrowserCacheLocation.LocalStorage,
    },
  },
  ['openid', 'profile', 'user', 'offline_access'],
)
  • User Credentials The cypess test user's credentials (email and password). I strongly recommend to create a dedicated Cypress test user with specific rights.

  • Configuration The configuration as provided to your msal instance. If you set the settings using envirenment variables (which you probably should), you might need to adjust the configuration accordingly for Cypress. See example below and take a look at the documentation cypress/environment-variables

import { Configuration, BrowserCacheLocation } from '@azure/msal-browser'

const msalConfig: Configuration = {
  auth: {
    clientId: Cypress.env('MSAL_CLIENT_ID'),
    authority: `https://login.microsoftonline.com/${Cypress.env('MSAL_TENANT_ID')}`,
  },
  cache: {
    cacheLocation: BrowserCacheLocation.LocalStorage,
    storeAuthStateInCookie: true,
  },
}

Session token

The session token (access_token) is exposes as alias sessionToken and you can get it like this:

  cy.get('@sessionToken').then(sessionToken => {
    // ... do whatever you want with it.
  })

Trouble-shoot

  • Scope The scope of the token. Make sure you include at least the openid, profile, user and offline_access
2.0.1

8 months ago

2.0.0

8 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.8-rc.0

1 year ago

1.0.7

1 year ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago