1.0.43 • Published 3 years ago

@workpathco/client v1.0.43

Weekly downloads
42
License
MIT
Repository
github
Last release
3 years ago

npm.io

Workpath Web Client

JavaScript client for OAuth authorization code flow.

This package was created to help single page applications connect to Workpath using oauth's authorization code flow.

Installation

npm install @workpathco/client --save

or

yarn add @workpathco/client

Usage example

First instantiate an authentication object passing the client id and redirect uri you've obtained from the Workpath Client Dashboard.

import { Authenticate } from "@workpathco/client"

const authentication = new Authenticate({
  client_id: "XXXXX-XXXXX-XXXXX-XXXXX", // insert your client id here
  redirect_uri: "https://your-redirect-uri.here", // insert your redirect uri added when creating your client
})

Next, use the instantiated authentication object to login:

authentication.login()

This will create a unique login url and redirect the user to the Workpath login page.

After the user signs in they will be redirected back to the specified redirect_uri where you will consume the request using the consume function as follows:

await authentication.consume()

Immediately after a successful authorization consumption you will be able to access the token by calling getToken as follows:

const token = authentication.memory.getToken()

This token is only set in memory so you will need to manage it's storage yourself. (Note: These token are valid for 24 hours at which point they will expire and the user will need to re-authenticate)

For instance, using session cookies:

cookie.set("_wp_token", JSON.stringify(token));

All subsequent authenticated requests can be made with the access_token added as an Authorization request header as follows:

Authorization: Bearer XXXX-XXXX-XXXX-XXXX

An example react implementation can be found here

1.0.43

3 years ago

1.0.42

3 years ago

1.0.41

4 years ago

1.0.40

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.26

4 years ago

1.0.27

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.10

4 years ago

1.0.12

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago