oada-id-client
JavaScript client library for OADA identity. Can be used both in NodeJS and in the browser.
Getting Started
Installation
The library is not yet published with npm
,
but it can be installed from the GitHub repo.
$ npm install OADA/oada-id-client-js
Browser Code Generation
The code to use in the browser can be generated with the following command:
$ npm run bundle
This will create the file dist/bundle.js
.
Examples
Connect Style "Middleware" Wrapper Usage
Version of the library functions which wrap the core functionality for use as connect style "middleware". This can be used in a NodeJS server using a compatible web development framework, such as express.
For a working example of using this wrapper, see the on server example.
getIDToken(domain, options)
Middleware for generating an ID token request against an OADA identity provider.
Parameters
domain
string of domain with which to log in the user.
The value passed to the function can be overridden by a query or form
parameter with a name of domain
.
options
object containing at least the following properties:
metadata
object containg client metadata, or string of asoftware_statement
JWTprivateKey
pem
string or buffer containing your client's PEM encoded private RSA keykid
string containing the key ID parameter, for finding the corresponding public key where your client is registered
params
Optional OpenID Connect parameters placed inparams
as string properties will be used (e.g.display
,prompt
,login_hint
)
Usage Example
var options = metadata: /* See spec linked above */ privateKey: pem: fs kid: 'key_id_corresponding_to_pem' ; app;
getAccessToken(domain, options)
Middleware for generating an access token request against an OADA compliant API.
Parameters
domain
string of domain from which to get an OADA API access token.
The value passed to the function can be overridden by a query or form
parameter with a name of domain
.
options
object containing at least the following properties:
metadata
object containg client metadata, or string of asoftware_statement
JWTprivateKey
pem
string or buffer containing your client's PEM encoded private RSA keykid
string containing the key ID parameter, for finding the corresponding public key where your client is registered
scope
space separated string of OAuth scopes for the request access token to have.params
Optional OpenID Connect parameters placed inparams
as string properties will be used (e.g.display
,prompt
,login_hint
)
Usage Example
var options = metadata: /* See spec linked above */ privateKey: pem: fs kid: 'key_id_corresponding_to_pem' scope: 'some.oada.defined.scope'; app;
handleRedirect()
Middleware for handling redirects from getIDToken
or getAccessToken
middlewares.
In most case you will apply this middleware in two locations,
one to receive getIDToken
redirects and
another to receive getAccessToken
redirects.
Usage Example
// Handle ID token redirectsapp;app; // Handle access token redirectsapp;app;
Browser Wrapper Usage
Version of the library functions which wrap the core functionality for easy use in the browser.
For a working example of using this wrapper, see the in browser example.
getIDToken(domain, options, callback)
Asynchronous function for generating an ID token request against an OADA identity provider.
Parameters
domain
string of domain with which to log in the user.
options
object containing at least the following properties:
metadata
object containg client metadata, or string of asoftware_statement
JWTparams
Optional OpenID Connect parameters placed inparams
as string properties will be used (e.g.display
,prompt
,login_hint
)
Optional OpenID Connect parameters placed in options as
string properties will be used (e.g. display
, prompt
, login_hint
).
callback
function of the form function(err, idToken)
.
Usage Example
var options = metadata: /* See spec linked above */ ; var domain; // Set domain based on text box, dropdown, etc. oadaIdClient;
getAccessToken(domain, options, callback)
Asynchronous function for generating an access token request against an OADA compliant API.
Parameters
domain
string of domain from which to get an OADA API access token.
The value passed to the function can be overridden by a query or form
parameter with a name of domain
.
options
object containing at least the following properties:
metadata
object containg client metadata, or string of asoftware_statement
JWTscope
space separated string of OAuth scopes for the request access token to have.params
Optional OpenID Connect parameters placed inparams
as string properties will be used (e.g.display
,prompt
,login_hint
)
callback
function of the form function(err, accessToken)
.
Usage Example
var options = metadata: /* See spec linked above */ scope: 'some.oada.defined.scope'; var domain; // Set domain based on text box, dropdown, etc. oadaIdClient;
handleRedirect()
Function for handling redirects generated by
getIDToken
or getAccessToken
function.
Simply needs to be called by the page served from the URL corresponding to
redirect_uri
.
Usage Example
<!-- Page served at redirect_uri for getIDToken and/or getAccessToken -->
Base Library Usage
Not yet documented.