uPortal-web-components

uPortal Open ID Connect

NPM Version Maven Central Build Status

A client side abstraction to efficiently get Open ID Connect tokens from uPortal

Installation

# installer avec npm
npm install @uportal/open-id-connect

# installer avec yarn
yarn add @uportal/open-id-connect

installer avec maven

<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>uportal__open-id-connect</artifactId>
    <version>{version number goes here}</version>
</dependency>

installer avec gradle

compile 'org.webjars.npm:uportal__open-id-connect:{version number goes here}'

Utilisation

utilisation avec ES5

var oidc = require('@uportal/open-id-connect');

// with a promise
oidc
  .default()
  .then(function (token) {
    console.log(token.encoded); // Raw JWT
    console.log(token.decoded); // parsed JSON
  })
  .catch(function (err) {
    console.error(err);
  });

// with a callback
oidc.default({}, function (err, token) {
  if (err) {
    console.error(err);
    return;
  }

  console.log(token.encoded);
  console.log(token.decoded);
});

utilisation avec ES6+

import oicd from '@uportal/open-id-connect';

// with default values
try {
  const { encoded, decoded } = await oidc();
  console.log(encoded);
  console.log(decoded);
} catch (err) {
  console.error(err);
}

// with options
try {
  const { encoded, decoded } = await oidc({
    userInfoApiUrl: '/uPortal/api/v5-1/userinfo',
    timeout: 5000,
    propertyTransforms: {
      example: JSON.parse,
    },
  });
  console.log(encoded);
  console.log(decoded);
} catch (err) {
  console.error(err);
}

API

oidc(options, callback); //-> Promise