Skip to main content

Authentication

@archibald/commerce/auth implements the @archibald/auth provider contract against the SAP Commerce OAuth server (authorizationserver): user login (password grant or OIDC) and client-credential access for anonymous traffic.

How to use

Register both providers with the AuthModuleCommerceUserAuthProvider authenticates users, CommerceStaticAuthProvider supplies the client-credentials token unauthenticated requests ride on:

// src/{platform}/server/module/server.tsx
import { AuthModule } from '@archibald/auth';
import { CommerceUserAuthProvider, CommerceStaticAuthProvider } from '@archibald/commerce/auth';

new AuthModule({
providers: [
new CommerceUserAuthProvider({
config: () => this.configService.get('hybris.api'),
credentials: () => this.configService.get('hybris.oauth')
}),
new CommerceStaticAuthProvider({
config: () => this.configService.get('hybris.api'),
credentials: () => this.configService.get('hybris.oauth')
})
],
options: () => ({
strategy: { type: 'header' },
token: { secret: this.configService.get('server.credentials.token.secret') },
refresh: { secret: this.configService.get('server.credentials.token.secret') }
})
});

For OIDC (authorization-code flow against the Hybris IdP or a mock), the provider discovers the endpoints from GET {hybris.api}/authorizationserver/oauth/ — the OIDC setup guide walks through it end to end.

The user provider is the extension seam: the shop template's portal platform subclasses it (CommerceB2BUserAuthProvider extends CommerceUserAuthProvider) to enrich the session with B2B org data.

API reference

ExportSideWhat it is
CommerceUser, auth interfacesclientTyped user/session shapes shared with your components
CommerceUserAuthProviderserverUserAuthProvider against the OCC OAuth server (password + OIDC); subclass to extend the session
CommerceStaticAuthProviderserverClient-credentials provider for anonymous OCC access
user mapper, user mocksserverOCC user → CommerceUser mapping and fixtures

Configuration

  • hybris.api — OCC/OAuth host, through config.
  • hybris.oauthclient_id, client_secret (inject via a {{VAR}} environment placeholder, never committed), optional scope/redirect_uri, through credentials.
  • server.credentials.token.secret — the 32-character JWE session secret the AuthModule requires.

Further documentation