Skip to content

Releases: commercelayer/commercelayer-js-auth

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

v6.0.0-beta.2

26 Mar 17:31
5471701
Compare
Choose a tag to compare
v6.0.0-beta.2 Pre-release
Pre-release

What's Changed

📝 Documentation

Full Changelog: v6.0.0-beta.1...v6.0.0-beta.2

v6.0.0-beta.1

26 Mar 15:58
a7d8850
Compare
Choose a tag to compare
v6.0.0-beta.1 Pre-release
Pre-release

What's Changed

🚀 Enhancement

Full Changelog: v6.0.0-beta.0...v6.0.0-beta.1

v6.0.0-beta.0

22 Mar 21:14
d561938
Compare
Choose a tag to compare
v6.0.0-beta.0 Pre-release
Pre-release

What's Changed

💥 Breaking Change

🚀 Enhancement

📝 Documentation

Full Changelog: v5.2.1...v6.0.0-beta.0

v5.2.1

18 Mar 14:36
38aae1d
Compare
Choose a tag to compare

What's Changed

🐛 Bug Fix

  • Add missing provisioning types by @pviti in #65

📝 Documentation

Full Changelog: v5.2.0...v5.2.1

v5.2.0

14 Mar 17:34
8804265
Compare
Choose a tag to compare

What's Changed

🚀 Enhancement

Full Changelog: v5.1.0...v5.2.0

v5.1.0

14 Mar 16:00
1ea9dc8
Compare
Choose a tag to compare

What's Changed

🚀 Enhancement

Full Changelog: v5.0.0...v5.1.0

v5.0.0

14 Mar 10:15
317d36f
Compare
Choose a tag to compare

What's Changed

💥 Breaking Change

  • Remove backward-compatibility. remove export default and named export authentication by @marcomontalbano in #59

Full Changelog: v4.3.0...v5.0.0

v4.3.0

12 Mar 18:58
cb96c45
Compare
Choose a tag to compare

What's Changed

🚀 Enhancement

Full Changelog: v4.2.2...v4.3.0