Skip to content

Releases: commercelayer/commercelayer-js-auth

v6.4.0

03 Sep 08:39
a68f7c1
Compare
Choose a tag to compare

What's Changed

🚀 Enhancement

Full Changelog: v6.3.1...v6.4.0

v6.3.1

15 Jul 08:29
b6f3675
Compare
Choose a tag to compare

What's Changed

🐛 Bug Fix

Full Changelog: v6.3.0...v6.3.1

v6.3.0

02 Jul 15:21
d61b466
Compare
Choose a tag to compare

What's Changed

🚀 Enhancement

Full Changelog: v6.2.2...v6.3.0

v6.2.2

20 May 13:47
4a05784
Compare
Choose a tag to compare

What's Changed

🚀 Enhancement

Full Changelog: v6.2.1...v6.2.2

v6.2.1

08 May 07:49
3bd70fc
Compare
Choose a tag to compare

What's Changed

📝 Documentation

Full Changelog: v6.2.0...v6.2.1

v6.2.0

22 Apr 12:00
e3882c2
Compare
Choose a tag to compare

What's Changed

🚀 Enhancement

Other Changes

Full Changelog: v6.1.1...v6.2.0

v6.1.1

17 Apr 11:15
804872c
Compare
Choose a tag to compare

What's Changed

🐛 Bug Fix

Full Changelog: v6.1.0...v6.1.1

v6.1.0

16 Apr 09:13
73af7d4
Compare
Choose a tag to compare

What's Changed

🚀 Enhancement

Full Changelog: v6.0.1...v6.1.0

v6.0.1

15 Apr 15:53
d9e3fb1
Compare
Choose a tag to compare

What's Changed

🐛 Bug Fix

  • The encodeBase64URLSafe method replaces the base64 instead of the payload by @marcomontalbano in #75

📝 Documentation

Full Changelog: v6.0.0...v6.0.1

v6.0.0

26 Mar 17:35
1a76499
Compare
Choose a tag to compare

What's Changed

💥 Breaking Change

🚀 Enhancement

📝 Documentation

💥 Breaking changes

This library now uses the new https://auth.commercelayer.io/oauth/token endpoint. We unified core and provisioning into a single authenticate method.

# no more valid
-  import { provisioning } from '@commercelayer/js-auth'

# no more valid
-  import { core } from '@commercelayer/js-auth'

# new syntax
+ import { authenticate } from '@commercelayer/js-auth'

Examples

Core authentication

import { authenticate } from '@commercelayer/js-auth'

const auth = await authenticate('client_credentials', {
  clientId: '{{ client_id }}',
  scope: 'market:id:1234'
})

Provisioning authentication

Read more about how to get the client id and secret.

import { authenticate } from '@commercelayer/js-auth'

const auth = await authenticate('client_credentials', {
  clientId: '{{ client_id }}',
  clientSecret: '{{ client_secret }}',
})

Typescript

import { authenticate, type AuthenticateOptions } from '@commercelayer/js-auth'

const options: AuthenticateOptions<'client_credentials'> = {
  clientId: '{{ client_id }}',
  scope: 'market:id:1234'
}

const auth = await authenticate('client_credentials', options)

Decode an access token

We added an helper method to decode an access token:

import { authenticate, jwtDecode, jwtIsSalesChannel } from '@commercelayer/js-auth'

const auth = await authenticate('client_credentials', {
  clientId: '{{ application_client_id }}',
  scope: '{{ application_scope }}'
})

const decodedJWT = jwtDecode(auth.accessToken)

if (jwtIsSalesChannel(decodedJWT.payload)) {
  console.log('organization slug is', decodedJWT.payload.organization.slug)
}

JWT bearer flow

JWT Bearer flow allows a client application to obtain an access token using a JSON Web Token (JWT) assertion.

We added support to the JWT bearer flow by introducing a new createAssertion method:

const assertion = await createAssertion({
  payload: {
    'https://commercelayer.io/claims': {
      owner: {
        type: 'Customer',
        id: '4tepftJsT2'
      },
      custom_claim: {
        customer: {
          first_name: 'John',
          last_name: 'Doe'
        }
      }
    }
  }
})

Once you created the assertion you can get an access token using the urn:ietf:params:oauth:grant-type:jwt-bearer grant type:

import { authenticate } from '@commercelayer/js-auth'

const auth = await authenticate('urn:ietf:params:oauth:grant-type:jwt-bearer', {
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
  scope: 'market:code:europe',
  assertion
})

console.log('My access token: ', auth.accessToken)
console.log('Expiration date: ', auth.expires)

Revoke an access token

We added the revoke method.

Any previously generated access tokens (refresh tokens included) can be revoked before their natural expiration date.

import { revoke } from '@commercelayer/js-auth'

await revoke({
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
  token: 'a-generated-access-token'
})

Full Changelog: v5.2.1...v6.0.0