Skip to content

Commit 630f502

Browse files
authored
implicit auth (#5)
* implicit auth * logging * updates
1 parent 05bb084 commit 630f502

12 files changed

Lines changed: 934 additions & 45 deletions

File tree

packages/b2c-tooling/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
"chokidar": "^5.0.0",
165165
"glob": "^13.0.0",
166166
"i18next": "^25.6.3",
167+
"open": "^11.0.0",
167168
"openapi-fetch": "^0.15.0",
168169
"pino": "^10.1.0",
169170
"pino-pretty": "^13.1.2"

packages/b2c-tooling/src/auth/index.ts

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,53 @@
88
*
99
* - {@link BasicAuthStrategy} - Username/password authentication for WebDAV operations
1010
* - {@link OAuthStrategy} - OAuth 2.0 client credentials for OCAPI and platform APIs
11+
* - {@link ImplicitOAuthStrategy} - Interactive browser-based OAuth for CLI/desktop apps
1112
* - {@link ApiKeyStrategy} - API key authentication for MRT services
1213
*
13-
* ## Usage
14+
* ## Strategy Resolution
1415
*
15-
* All strategies implement the {@link AuthStrategy} interface, allowing you to
16-
* switch authentication methods without changing your code:
16+
* Use {@link resolveAuthStrategy} to automatically select the best strategy based on
17+
* available credentials and allowed methods:
1718
*
1819
* ```typescript
19-
* import { BasicAuthStrategy, OAuthStrategy } from '@salesforce/b2c-tooling';
20+
* import { resolveAuthStrategy } from '@salesforce/b2c-tooling';
2021
*
21-
* // For WebDAV operations (code upload)
22-
* const basicAuth = new BasicAuthStrategy('username', 'access-key');
22+
* // Automatically picks client-credentials if secret available, otherwise implicit
23+
* const strategy = resolveAuthStrategy({
24+
* clientId: 'your-client-id',
25+
* clientSecret: process.env.CLIENT_SECRET, // may be undefined
26+
* });
27+
*
28+
* // Force a specific method
29+
* const implicitOnly = resolveAuthStrategy(
30+
* { clientId: 'your-client-id' },
31+
* { allowedMethods: ['implicit'] }
32+
* );
33+
* ```
34+
*
35+
* ## Direct Usage
36+
*
37+
* All strategies implement the {@link AuthStrategy} interface:
2338
*
24-
* // For OCAPI operations (sites, jobs)
39+
* ```typescript
40+
* import { OAuthStrategy, ImplicitOAuthStrategy } from '@salesforce/b2c-tooling';
41+
*
42+
* // For automated/server usage (client credentials)
2543
* const oauthAuth = new OAuthStrategy({
2644
* clientId: 'your-client-id',
2745
* clientSecret: 'your-client-secret',
2846
* });
47+
*
48+
* // For interactive/CLI usage (opens browser)
49+
* const implicitAuth = new ImplicitOAuthStrategy({
50+
* clientId: 'your-client-id',
51+
* });
2952
* ```
3053
*
3154
* @module auth
3255
*/
56+
57+
// Types
3358
export type {
3459
AuthStrategy,
3560
AccessTokenResponse,
@@ -38,8 +63,19 @@ export type {
3863
BasicAuthConfig,
3964
OAuthAuthConfig,
4065
ApiKeyAuthConfig,
66+
AuthMethod,
67+
AuthCredentials,
4168
} from './types.js';
69+
export {ALL_AUTH_METHODS} from './types.js';
70+
71+
// Strategies
4272
export {BasicAuthStrategy} from './basic.js';
4373
export {OAuthStrategy, decodeJWT} from './oauth.js';
4474
export type {OAuthConfig} from './oauth.js';
75+
export {ImplicitOAuthStrategy} from './oauth-implicit.js';
76+
export type {ImplicitOAuthConfig} from './oauth-implicit.js';
4577
export {ApiKeyStrategy} from './api-key.js';
78+
79+
// Resolution helpers
80+
export {resolveAuthStrategy, checkAvailableAuthMethods} from './resolve.js';
81+
export type {ResolveAuthStrategyOptions, AvailableAuthMethods} from './resolve.js';

0 commit comments

Comments
 (0)