@miaaguard/ui-core
TypeScript icon, indicating that this package has built-in type declarations

22.3.1 • Public • Published

@miaaguard/ui-core

This package offers a JavaScript SDK to facilitate integration with miaa Guards CloudWare components.

Installation

Install using yarn or npm

$ npm i @miaaguard/ui-core

Auth

import { auth } from '@miaaguard/ui-core';

auth.init({
    authority: '<miaa PolicyGate endpoint>',
    client_id: 'your login client ID',
    audiences: {
        '__default__': {
            scope: 'openid email profile'
        }
    }
});

auth.login();

Settings

The following settings can be passed at initialization time

Name Required Type Description
authority string The base URI of your miaa PolicyGate instance
client_id string The id of the login client used to connect to PolicyGate
audiences object OIDC audience configuration object

Additionally, the settings may contain any of the settings defined by the OIDC client library. These settings can be applied generally, for all audiences, by adding them to the root of the settings object. Alternatively, settings can be overridden per audience by defining them on the corresponding object, as shown in the example below:

auth.init({
    post_logout_redirect_uri: 'https://your-redirect.uri',
    audiences: {
        '__default__': {
            scope: 'openid email profile'
        },
        foobar: {
            scope: 'openid',
            post_logout_redirect_uri: 'https://your-specific-redirect.uri/for-foobar'
        }
    }
})

In the example above, the default audience will use https://your-redirect.uri as its post_logout_redirect_uri, while the foobar audience will use https://your-specific-redirect.uri/for-foobar.

Methods

Name Returns Description
init(settings) Promise Configures the authorization module and will log the user in if they have a valid session with PolicyGate
login(redirect?: boolean, state?: any) Promise Starts the login process via popup (default) or redirect. Default values are "redirect": false and "state": undefined. The state can be any data you want to associate with the request.
logout(silent?: boolean) Promise Starts the logout process via the popup flow. If true is passed, the logout process will be handled via a hidden iframe
isLoggedIn() Promise Returns true if the user has a valid session with PolicyGate
getAccessToken(audience?: string) Promise Returns the access token corresponding to the audience. If no audience is specified, the default audience is assumed
getUser() Promise Returns the profile information stored in the identity token of the default audience

ProfileConnectProxy

import { ProfileConnectProxy } from '@miaaguard/ui-core';

const profile = new ProfileConnectProxy({
    baseUri: '<miaa ProfileConnect API endpoint>',
    getBearerHeader: () => return new Headers({ Authorization: 'Bearer <JWT>' }),
    profileType: 'profile'
});

// retrieve the profile
profile.get('id')
    .then(profile => console.log(profile));

// save a profile
profile.save('id', { name: 'John Doe' })
    .then(profile => console.log(profile));

Settings

The following settings can be passed at construction time

Name Required Type Description
baseUri string The base URI of your miaa cloudware instance
getBearerHeader function A function returning a (Promise for a) Headers object containing at least an Authorization header. Defaults to a Headers object with a Bearer Authorization header with the value of the access token for the default audience
profileType string The type of the profile you are creating a Proxy for. Defaults to profile

Methods

The following methods are available on a Proxy instance. All methods return a Promise.

Name Returns Description
get(id) Promise Retrieves the profile for the specified id
save(id, data) Promise Saves the data to the profile for the specified id and returns the updated profile

Readme

Keywords

none

Package Sidebar

Install

npm i @miaaguard/ui-core

Weekly Downloads

17

Version

22.3.1

License

ISC

Unpacked Size

26.9 kB

Total Files

4

Last publish

Collaborators