@adonisjs/ally 5.1.0 → 6.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/build/{chunk-N72DEJC2.js → chunk-KSJ4CFTC.js} +45 -8
  2. package/build/{chunk-VHORNQLN.js → chunk-KWRXS6EG.js} +65 -28
  3. package/build/{chunk-PZ5AY32C.js → chunk-MLKGABMK.js} +0 -1
  4. package/build/{chunk-NZT2DLWM.js → chunk-SZ4YJCVU.js} +15 -3
  5. package/build/chunk-WM3V3APX.js +210 -0
  6. package/build/index.d.ts +8 -8
  7. package/build/index.js +6 -8
  8. package/build/providers/ally_provider.d.ts +1 -1
  9. package/build/providers/ally_provider.js +3 -4
  10. package/build/src/abstract_drivers/oauth1.d.ts +115 -49
  11. package/build/src/abstract_drivers/oauth2.d.ts +121 -50
  12. package/build/src/ally_manager.d.ts +31 -4
  13. package/build/src/debug.d.ts +9 -0
  14. package/build/src/define_config.d.ts +45 -11
  15. package/build/src/drivers/discord.d.ts +76 -11
  16. package/build/src/drivers/discord.js +47 -12
  17. package/build/src/drivers/facebook.d.ts +73 -10
  18. package/build/src/drivers/facebook.js +44 -11
  19. package/build/src/drivers/github.d.ts +85 -13
  20. package/build/src/drivers/github.js +56 -14
  21. package/build/src/drivers/google.d.ts +80 -11
  22. package/build/src/drivers/google.js +50 -12
  23. package/build/src/drivers/linked_in.d.ts +76 -10
  24. package/build/src/drivers/linked_in.js +47 -12
  25. package/build/src/drivers/linked_in_openid_connect.d.ts +72 -9
  26. package/build/src/drivers/linked_in_openid_connect.js +42 -10
  27. package/build/src/drivers/spotify.d.ts +73 -10
  28. package/build/src/drivers/spotify.js +44 -11
  29. package/build/src/drivers/twitter.d.ts +65 -8
  30. package/build/src/drivers/twitter.js +37 -9
  31. package/build/src/errors.d.ts +10 -2
  32. package/build/src/redirect_request.d.ts +47 -7
  33. package/build/src/types.d.ts +1 -1
  34. package/build/src/types.js +0 -1
  35. package/package.json +57 -68
  36. package/build/chunk-GWAQFMNS.js +0 -164
  37. package/build/chunk-GWAQFMNS.js.map +0 -1
  38. package/build/chunk-N72DEJC2.js.map +0 -1
  39. package/build/chunk-NZT2DLWM.js.map +0 -1
  40. package/build/chunk-PZ5AY32C.js.map +0 -1
  41. package/build/chunk-VHORNQLN.js.map +0 -1
  42. package/build/index.js.map +0 -1
  43. package/build/providers/ally_provider.js.map +0 -1
  44. package/build/src/drivers/discord.js.map +0 -1
  45. package/build/src/drivers/facebook.js.map +0 -1
  46. package/build/src/drivers/github.js.map +0 -1
  47. package/build/src/drivers/google.js.map +0 -1
  48. package/build/src/drivers/linked_in.js.map +0 -1
  49. package/build/src/drivers/linked_in_openid_connect.js.map +0 -1
  50. package/build/src/drivers/spotify.js.map +0 -1
  51. package/build/src/drivers/twitter.js.map +0 -1
  52. package/build/src/types.js.map +0 -1
@@ -1,145 +1,211 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
2
  import { Oauth1Client } from '@poppinss/oauth-client/oauth1';
3
- import { AllyUserContract, Oauth1AccessToken, Oauth1DriverConfig, ApiRequestContract, AllyDriverContract, RedirectRequestContract } from '../types.js';
4
- import { RedirectRequest } from '../redirect_request.js';
3
+ import { type AllyUserContract, type Oauth1AccessToken, type Oauth1DriverConfig, type ApiRequestContract, type AllyDriverContract, type RedirectRequestContract } from '../types.ts';
4
+ import { RedirectRequest } from '../redirect_request.ts';
5
5
  /**
6
- * Abstract implementation for an Oauth1 driver
6
+ * Abstract base class for implementing OAuth1 social authentication drivers.
7
+ * Extends the OAuth1 client to provide AdonisJS-specific functionality like
8
+ * token management via cookies and integration with HTTP context.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * export class CustomDriver extends Oauth1Driver<CustomToken, CustomScopes> {
13
+ * protected oauthTokenCookieName = 'custom_oauth_token'
14
+ * protected oauthTokenParamName = 'oauth_token'
15
+ * protected oauthTokenVerifierName = 'oauth_verifier'
16
+ * protected errorParamName = 'error'
17
+ * protected requestTokenUrl = 'https://provider.com/oauth/request_token'
18
+ * protected authorizeUrl = 'https://provider.com/oauth/authorize'
19
+ * protected accessTokenUrl = 'https://provider.com/oauth/access_token'
20
+ * protected scopeParamName = ''
21
+ * protected scopesSeparator = ' '
22
+ *
23
+ * async user() {
24
+ * // Implementation
25
+ * }
26
+ * }
27
+ * ```
7
28
  */
8
29
  export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scopes extends string> extends Oauth1Client<Token> implements AllyDriverContract<Token, Scopes> {
9
30
  #private;
10
31
  protected ctx: HttpContext;
11
32
  config: Oauth1DriverConfig;
12
33
  /**
13
- * The cookie name for storing the "oauth_token". Must be unique for your
14
- * driver. One option is to prefix the driver name. For example:
15
- * `twitter_oauth_token`
34
+ * The cookie name for storing the OAuth token. Must be unique for
35
+ * your driver to avoid conflicts. For example: `twitter_oauth_token`
16
36
  */
17
37
  protected abstract oauthTokenCookieName: string;
18
38
  /**
19
- * Name of the "oauth_token" param. This is the query string value post
20
- * authorization redirect
39
+ * The query parameter name for the OAuth token returned after
40
+ * authorization redirect. This is typically 'oauth_token'.
21
41
  */
22
42
  protected abstract oauthTokenParamName: string;
23
43
  /**
24
- * Name of the "oauth_verifier" param. This is the query string value post
25
- * authorization redirect
44
+ * The query parameter name for the OAuth verifier returned after
45
+ * authorization redirect. This is typically 'oauth_verifier'.
26
46
  */
27
47
  protected abstract oauthTokenVerifierName: string;
28
48
  /**
29
- * The parameter name from which to fetch the error message or error code
30
- * post redirect.
31
- *
32
- * You must check the auth provider docs to find it
49
+ * The query parameter name for error messages returned by the provider
50
+ * after authorization redirect.
33
51
  */
34
52
  protected abstract errorParamName: string;
35
53
  /**
36
- * Request token URL for the auth provider. The initial set of tokens
37
- * are generated from this url
54
+ * The OAuth provider's endpoint for obtaining a request token.
55
+ * This is the first step in the OAuth1 flow.
38
56
  */
39
57
  protected abstract requestTokenUrl: string;
40
58
  /**
41
- * Authorization URL for the auth provider. The user will be redirected
42
- * to this URL
59
+ * The OAuth provider's authorization URL where users are redirected
60
+ * to grant permissions.
43
61
  */
44
62
  protected abstract authorizeUrl: string;
45
63
  /**
46
- * The URL to hit to get an access token
64
+ * The OAuth provider's endpoint for exchanging the request token
65
+ * and verifier for an access token.
47
66
  */
48
67
  protected abstract accessTokenUrl: string;
49
68
  /**
50
- * The query param name for defining the Authorization scopes.
51
- * Mostly it is `scope`. Leave to empty string when scopes
52
- * are not applicable
69
+ * The query parameter name for defining authorization scopes.
70
+ * Leave as empty string if scopes are not supported by the provider.
53
71
  */
54
72
  protected abstract scopeParamName: string;
55
73
  /**
56
- * The identifier for joining multiple scopes. Mostly it is a space.
74
+ * The separator character for joining multiple scopes. This is
75
+ * typically a space ' '.
57
76
  */
58
77
  protected abstract scopesSeparator: string;
59
78
  /**
60
- * Returns details for the authorized user
79
+ * Fetch the user details from the OAuth provider using the
80
+ * authorization from the current request.
81
+ *
82
+ * @param callback - Optional callback to customize the API request
61
83
  */
62
84
  abstract user(callback?: (request: ApiRequestContract) => void): Promise<AllyUserContract<Token>>;
63
85
  /**
64
- * Finds the user by access token
86
+ * Fetch user details using an existing access token and secret.
87
+ * This is the OAuth1 equivalent of `userFromToken`.
88
+ *
89
+ * @param token - The access token
90
+ * @param secret - The token secret
91
+ * @param callback - Optional callback to customize the API request
65
92
  */
66
93
  abstract userFromTokenAndSecret(token: string, secret: string, callback?: (request: ApiRequestContract) => void): Promise<AllyUserContract<{
67
94
  token: string;
68
95
  secret: string;
69
96
  }>>;
70
97
  /**
71
- * Find if the current error code is for access denied
98
+ * Check if the current error indicates that the user denied access.
99
+ * Different providers use different error codes for access denial.
72
100
  */
73
101
  abstract accessDenied(): boolean;
74
102
  /**
75
- * Oauth client version
103
+ * OAuth protocol version identifier
76
104
  */
77
105
  version: "oauth1";
78
106
  /**
79
- * The value of "oauth_token" and "oauth_secret" from the cookies
107
+ * Cached OAuth token and secret values read from cookies
80
108
  */
81
109
  protected oauthTokenCookieValue?: string;
82
110
  protected oauthSecretCookieValue?: string;
83
111
  /**
84
- * The cookie name for storing the secret
112
+ * The cookie name for storing the OAuth token secret.
113
+ * Automatically derived from the token cookie name.
85
114
  */
86
115
  protected get oauthSecretCookieName(): string;
116
+ /**
117
+ * @param ctx - The current HTTP context
118
+ * @param config - OAuth1 driver configuration
119
+ */
87
120
  constructor(ctx: HttpContext, config: Oauth1DriverConfig);
88
121
  /**
89
- * The Oauth1Client will use the instance returned from this method to
90
- * build the redirect url
122
+ * Creates a URL builder instance for constructing authorization URLs
123
+ * with scope support.
124
+ *
125
+ * @param url - The base authorization URL
91
126
  */
92
127
  protected urlBuilder(url: string): RedirectRequest<string>;
93
128
  /**
94
- * Loads the value of state from the cookie and removes it right
95
- * away. We read the cookie value and clear it during the
96
- * current request lifecycle.
97
- *
98
- * :::::
99
- * NOTE
100
- * :::::
129
+ * Loads the OAuth token and secret from encrypted cookies and immediately
130
+ * clears the cookies. This must be called by child classes in their
131
+ * constructor to enable token verification.
101
132
  *
102
- * This child class must call this method inside the constructor.
133
+ * @example
134
+ * ```ts
135
+ * constructor(ctx: HttpContext, config: DriverConfig) {
136
+ * super(ctx, config)
137
+ * this.loadState()
138
+ * }
139
+ * ```
103
140
  */
104
141
  protected loadState(): void;
105
142
  /**
106
- * Perform stateless authentication. Only applicable for Oauth1 client
143
+ * OAuth1 does not support stateless authentication due to the
144
+ * three-legged authentication flow requiring token persistence.
107
145
  */
108
146
  stateless(): never;
109
147
  /**
110
- * Returns the redirect URL for the request.
148
+ * Get the authorization redirect URL without performing the redirect.
149
+ * Useful when you need to manually handle the redirect or use the URL
150
+ * in a different context.
151
+ *
152
+ * @param callback - Optional callback to customize the redirect request
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * const url = await ally.use('twitter').redirectUrl()
157
+ * ```
111
158
  */
112
159
  redirectUrl(callback?: (request: RedirectRequestContract<Scopes>) => void): Promise<string>;
113
160
  /**
114
- * Redirect user for authorization.
161
+ * Redirect the user to the OAuth provider's authorization page.
162
+ * The request token is automatically obtained and stored in cookies.
163
+ *
164
+ * @param callback - Optional callback to customize the redirect request
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * await ally.use('twitter').redirect()
169
+ * ```
115
170
  */
116
171
  redirect(callback?: (request: RedirectRequestContract<Scopes>) => void): Promise<void>;
117
172
  /**
118
- * Find if there is a state mismatch
173
+ * Check if the OAuth token from the callback matches the token
174
+ * stored in the cookie.
119
175
  */
120
176
  stateMisMatch(): boolean;
121
177
  /**
122
- * Find if there is an error post redirect
178
+ * Check if an error was returned by the OAuth provider.
123
179
  */
124
180
  hasError(): boolean;
125
181
  /**
126
- * Get the post redirect error
182
+ * Get the error code or message returned by the OAuth provider.
183
+ * Returns 'unknown_error' if no verifier is present and no error was specified.
127
184
  */
128
185
  getError(): string | null;
129
186
  /**
130
- * Returns the "oauth_verifier" token
187
+ * Get the OAuth verifier from the callback request.
131
188
  */
132
189
  getCode(): string | null;
133
190
  /**
134
- * Find it the code exists
191
+ * Check if the OAuth verifier is present in the callback request.
135
192
  */
136
193
  hasCode(): boolean;
137
194
  /**
138
- * Get access token
195
+ * Exchange the request token and verifier for an access token.
196
+ * This method validates the token and checks for errors before
197
+ * making the request.
198
+ *
199
+ * @param callback - Optional callback to customize the token request
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * const token = await ally.use('twitter').accessToken()
204
+ * ```
139
205
  */
140
206
  accessToken(callback?: (request: ApiRequestContract) => void): Promise<Token>;
141
207
  /**
142
- * Not applicable with Oauth1
208
+ * Not applicable with OAuth1. Use `userFromTokenAndSecret` instead.
143
209
  */
144
210
  userFromToken(): Promise<never>;
145
211
  }
@@ -1,142 +1,213 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
2
  import { Oauth2Client } from '@poppinss/oauth-client/oauth2';
3
- import { AllyUserContract, Oauth2AccessToken, Oauth2DriverConfig, ApiRequestContract, AllyDriverContract, RedirectRequestContract } from '../types.js';
4
- import { RedirectRequest } from '../redirect_request.js';
3
+ import { type AllyUserContract, type Oauth2AccessToken, type Oauth2DriverConfig, type ApiRequestContract, type AllyDriverContract, type RedirectRequestContract } from '../types.ts';
4
+ import { RedirectRequest } from '../redirect_request.ts';
5
5
  /**
6
- * Abstract implementation for an Oauth2 driver
6
+ * Abstract base class for implementing OAuth2 social authentication drivers.
7
+ * Extends the OAuth2 client to provide AdonisJS-specific functionality like
8
+ * CSRF protection, state management, and integration with HTTP context.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * export class CustomDriver extends Oauth2Driver<CustomToken, CustomScopes> {
13
+ * protected stateCookieName = 'custom_oauth_state'
14
+ * protected stateParamName = 'state'
15
+ * protected errorParamName = 'error'
16
+ * protected codeParamName = 'code'
17
+ * protected authorizeUrl = 'https://provider.com/oauth/authorize'
18
+ * protected accessTokenUrl = 'https://provider.com/oauth/token'
19
+ * protected scopeParamName = 'scope'
20
+ * protected scopesSeparator = ' '
21
+ *
22
+ * async user() {
23
+ * // Implementation
24
+ * }
25
+ * }
26
+ * ```
7
27
  */
8
28
  export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scopes extends string> extends Oauth2Client<Token> implements AllyDriverContract<Token, Scopes> {
9
29
  #private;
10
30
  protected ctx: HttpContext;
11
31
  config: Oauth2DriverConfig;
12
32
  /**
13
- * Is the authorization process stateless?
33
+ * Whether the authorization process is stateless. When true,
34
+ * state verification via cookies is disabled.
14
35
  */
15
36
  protected isStateless: boolean;
16
37
  /**
17
- * The cookie name for storing the CSRF token. Must be unique for your
18
- * driver. One option is to prefix the driver name. For example:
19
- * `gh_oauth_state`
38
+ * The cookie name for storing the CSRF state token. Must be unique
39
+ * for your driver to avoid conflicts. For example: `gh_oauth_state`
20
40
  */
21
41
  protected abstract stateCookieName: string;
22
42
  /**
23
- * The parameter in which to send the state to the oauth provider. The same
24
- * input is used to retrieve the state post redirect as well.
25
- *
26
- * You must check the auth provider docs to find it
43
+ * The query parameter name for sending the state to the OAuth provider.
44
+ * This is typically 'state' but varies by provider. Check the provider's
45
+ * OAuth documentation.
27
46
  */
28
47
  protected abstract stateParamName: string;
29
48
  /**
30
- * The parameter name from which to fetch the error message or error code
31
- * post redirect.
32
- *
33
- * You must check the auth provider docs to find it
49
+ * The query parameter name for error messages returned by the provider
50
+ * after authorization redirect. This is typically 'error'.
34
51
  */
35
52
  protected abstract errorParamName: string;
36
53
  /**
37
- * The parameter name from which to fetch the authorization code. It is usually
38
- * named as "code".
39
- *
40
- * You must check the auth provider docs to find it
54
+ * The query parameter name for the authorization code returned by the
55
+ * provider. This is typically 'code'.
41
56
  */
42
57
  protected abstract codeParamName: string;
43
58
  /**
44
- * Authorization URL for the auth provider. The user will be redirected
45
- * to this URL
59
+ * The OAuth provider's authorization URL where users are redirected
60
+ * to grant permissions.
46
61
  */
47
62
  protected abstract authorizeUrl: string;
48
63
  /**
49
- * The URL to hit to get an access token
64
+ * The OAuth provider's endpoint for exchanging the authorization code
65
+ * for an access token.
50
66
  */
51
67
  protected abstract accessTokenUrl: string;
52
68
  /**
53
- * The query param name for defining the Authorization scopes.
54
- * Mostly it is `scope`
69
+ * The query parameter name for defining authorization scopes.
70
+ * This is typically 'scope'.
55
71
  */
56
72
  protected abstract scopeParamName: string;
57
73
  /**
58
- * The identifier for joining multiple scopes. Mostly it is a space.
74
+ * The separator character for joining multiple scopes. This is
75
+ * typically a space ' ' or comma ','.
59
76
  */
60
77
  protected abstract scopesSeparator: string;
61
78
  /**
62
- * Returns details for the authorized user
79
+ * Fetch the user details from the OAuth provider using the
80
+ * authorization code from the current request.
81
+ *
82
+ * @param callback - Optional callback to customize the API request
63
83
  */
64
84
  abstract user(callback?: (request: ApiRequestContract) => void): Promise<AllyUserContract<Token>>;
65
85
  /**
66
- * Finds the user by access token
86
+ * Fetch user details using an existing access token. Useful for
87
+ * verifying tokens or fetching user info for already authenticated users.
88
+ *
89
+ * @param token - The access token
90
+ * @param callback - Optional callback to customize the API request
67
91
  */
68
92
  abstract userFromToken(token: string, callback?: (request: ApiRequestContract) => void): Promise<AllyUserContract<{
69
93
  token: string;
70
94
  type: 'bearer';
71
95
  }>>;
72
96
  /**
73
- * Find if the current error code is for access denied
97
+ * Check if the current error indicates that the user denied access.
98
+ * Different providers use different error codes for access denial.
74
99
  */
75
100
  abstract accessDenied(): boolean;
76
101
  /**
77
- * Oauth client version
102
+ * OAuth protocol version identifier
78
103
  */
79
104
  version: "oauth2";
80
105
  /**
81
- * The value of state read from the cookies.
106
+ * Cached state value read from the cookie
82
107
  */
83
108
  protected stateCookieValue?: string;
109
+ /**
110
+ * @param ctx - The current HTTP context
111
+ * @param config - OAuth2 driver configuration
112
+ */
84
113
  constructor(ctx: HttpContext, config: Oauth2DriverConfig);
85
114
  /**
86
- * The Oauth2Client will use the instance returned from this method to
87
- * build the redirect url
115
+ * Creates a URL builder instance for constructing authorization URLs
116
+ * with scope support.
117
+ *
118
+ * @param url - The base authorization URL
88
119
  */
89
120
  protected urlBuilder(url: string): RedirectRequest<string>;
90
121
  /**
91
- * Loads the value of state from the cookie and removes it right
92
- * away. We read the cookie value and clear it during the
93
- * current request lifecycle.
122
+ * Loads the state value from the encrypted cookie and immediately clears
123
+ * the cookie. This must be called by child classes in their constructor
124
+ * to enable CSRF protection.
94
125
  *
95
- * :::::
96
- * NOTE
97
- * :::::
98
- *
99
- * This child class must call this method inside the constructor.
126
+ * @example
127
+ * ```ts
128
+ * constructor(ctx: HttpContext, config: DriverConfig) {
129
+ * super(ctx, config)
130
+ * this.loadState()
131
+ * }
132
+ * ```
100
133
  */
101
134
  protected loadState(): void;
102
135
  /**
103
- * Perform stateless authentication. Only applicable for Oauth2 client
136
+ * Enable stateless authentication by disabling CSRF state verification.
137
+ * Only use this in scenarios where state verification is not required.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * await ally.use('github').stateless().redirect()
142
+ * ```
104
143
  */
105
144
  stateless(): this;
106
145
  /**
107
- * Returns the redirect URL for the request.
146
+ * Get the authorization redirect URL without performing the redirect.
147
+ * Useful when you need to manually handle the redirect or use the URL
148
+ * in a different context.
149
+ *
150
+ * @param callback - Optional callback to customize the redirect request
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * const url = await ally.use('github').redirectUrl((request) => {
155
+ * request.scopes(['user:email'])
156
+ * })
157
+ * ```
108
158
  */
109
159
  redirectUrl(callback?: (request: RedirectRequestContract<Scopes>) => void): Promise<string>;
110
160
  /**
111
- * Redirect user for authorization.
161
+ * Redirect the user to the OAuth provider's authorization page.
162
+ * The state parameter is automatically set for CSRF protection.
163
+ *
164
+ * @param callback - Optional callback to customize the redirect request
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * await ally.use('github').redirect((request) => {
169
+ * request.scopes(['user:email', 'read:org'])
170
+ * request.param('allow_signup', 'false')
171
+ * })
172
+ * ```
112
173
  */
113
174
  redirect(callback?: (request: RedirectRequestContract<Scopes>) => void): Promise<void>;
114
175
  /**
115
- * Find if there is a state mismatch
176
+ * Check if the state parameter from the callback matches the state
177
+ * stored in the cookie. Returns false in stateless mode.
116
178
  */
117
179
  stateMisMatch(): boolean;
118
180
  /**
119
- * Find if there is an error post redirect
181
+ * Check if an error was returned by the OAuth provider.
120
182
  */
121
183
  hasError(): boolean;
122
184
  /**
123
- * Get the post redirect error
185
+ * Get the error code or message returned by the OAuth provider.
186
+ * Returns 'unknown_error' if no code is present and no error was specified.
124
187
  */
125
188
  getError(): string | null;
126
189
  /**
127
- * Returns the authorization code
190
+ * Get the authorization code from the callback request.
128
191
  */
129
192
  getCode(): string | null;
130
193
  /**
131
- * Find it the code exists
194
+ * Check if the authorization code is present in the callback request.
132
195
  */
133
196
  hasCode(): boolean;
134
197
  /**
135
- * Get access token
198
+ * Exchange the authorization code for an access token. This method
199
+ * validates the state and checks for errors before making the request.
200
+ *
201
+ * @param callback - Optional callback to customize the token request
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * const token = await ally.use('github').accessToken()
206
+ * ```
136
207
  */
137
208
  accessToken(callback?: (request: ApiRequestContract) => void): Promise<Token>;
138
209
  /**
139
- * Not applicable with Oauth2
210
+ * Not applicable with OAuth2. Use `userFromToken` instead.
140
211
  */
141
212
  userFromTokenAndSecret(): Promise<never>;
142
213
  }
@@ -1,15 +1,42 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
- import type { AllyManagerDriverFactory } from './types.js';
2
+ import type { AllyManagerDriverFactory } from './types.ts';
3
3
  /**
4
- * AllyManager is used to create instances of a social drivers during an
5
- * HTTP request. The drivers are cached during the lifecycle of a request.
4
+ * AllyManager is used to create and manage social authentication driver
5
+ * instances during an HTTP request. The drivers are cached during the
6
+ * lifecycle of a request to avoid creating duplicate instances.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * router.get('/github/redirect', ({ ally }) => {
11
+ * return ally.use('github').redirect()
12
+ * })
13
+ *
14
+ * router.get('/github/callback', async ({ ally }) => {
15
+ * const github = ally.use('github')
16
+ * const user = await github.user()
17
+ * return user
18
+ * })
19
+ * ```
6
20
  */
7
21
  export declare class AllyManager<KnownSocialProviders extends Record<string, AllyManagerDriverFactory>> {
8
22
  #private;
9
23
  config: KnownSocialProviders;
24
+ /**
25
+ * @param config - Map of provider names to driver factory functions
26
+ * @param ctx - The current HTTP context
27
+ */
10
28
  constructor(config: KnownSocialProviders, ctx: HttpContext);
11
29
  /**
12
- * Returns the driver instance of a social provider
30
+ * Get a driver instance for the specified social provider. The driver
31
+ * instance is cached for the duration of the HTTP request.
32
+ *
33
+ * @param provider - The name of the social provider (e.g., 'github', 'google')
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const github = ally.use('github')
38
+ * await github.redirect()
39
+ * ```
13
40
  */
14
41
  use<SocialProvider extends keyof KnownSocialProviders>(provider: SocialProvider): ReturnType<KnownSocialProviders[SocialProvider]>;
15
42
  }
@@ -1,2 +1,11 @@
1
+ /**
2
+ * Debug logger for the Ally package. Set the NODE_DEBUG environment
3
+ * variable to "adonisjs:ally" to enable debug logs.
4
+ *
5
+ * @example
6
+ * ```sh
7
+ * NODE_DEBUG=adonisjs:ally node your-app.js
8
+ * ```
9
+ */
1
10
  declare const _default: import("util").DebugLogger;
2
11
  export default _default;
@@ -1,14 +1,14 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
2
  import type { ConfigProvider } from '@adonisjs/core/types';
3
- import type { GoogleDriver } from './drivers/google.js';
4
- import type { GithubDriver } from './drivers/github.js';
5
- import type { SpotifyDriver } from './drivers/spotify.js';
6
- import type { TwitterDriver } from './drivers/twitter.js';
7
- import type { DiscordDriver } from './drivers/discord.js';
8
- import type { FacebookDriver } from './drivers/facebook.js';
9
- import type { LinkedInDriver } from './drivers/linked_in.js';
10
- import type { LinkedInOpenidConnectDriver } from './drivers/linked_in_openid_connect.js';
11
- import type { GoogleDriverConfig, GithubDriverConfig, SpotifyDriverConfig, DiscordDriverConfig, TwitterDriverConfig, LinkedInDriverConfig, LinkedInOpenidConnectDriverConfig, FacebookDriverConfig, AllyManagerDriverFactory } from './types.js';
3
+ import type { GoogleDriver } from './drivers/google.ts';
4
+ import type { GithubDriver } from './drivers/github.ts';
5
+ import type { SpotifyDriver } from './drivers/spotify.ts';
6
+ import type { TwitterDriver } from './drivers/twitter.ts';
7
+ import type { DiscordDriver } from './drivers/discord.ts';
8
+ import type { FacebookDriver } from './drivers/facebook.ts';
9
+ import type { LinkedInDriver } from './drivers/linked_in.ts';
10
+ import type { LinkedInOpenidConnectDriver } from './drivers/linked_in_openid_connect.ts';
11
+ import type { GoogleDriverConfig, GithubDriverConfig, SpotifyDriverConfig, DiscordDriverConfig, TwitterDriverConfig, LinkedInDriverConfig, LinkedInOpenidConnectDriverConfig, FacebookDriverConfig, AllyManagerDriverFactory } from './types.ts';
12
12
  /**
13
13
  * Shape of config after it has been resolved from
14
14
  * the config provider
@@ -17,11 +17,45 @@ type ResolvedConfig<KnownSocialProviders extends Record<string, AllyManagerDrive
17
17
  [K in keyof KnownSocialProviders]: KnownSocialProviders[K] extends ConfigProvider<infer A> ? A : KnownSocialProviders[K];
18
18
  };
19
19
  /**
20
- * Define config for the ally
20
+ * Define configuration for Ally social authentication providers.
21
+ * This function accepts a map of provider names to their factory
22
+ * functions or config providers.
23
+ *
24
+ * @param config - An object mapping provider names to driver factories
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * export default defineConfig({
29
+ * github: services.github({
30
+ * clientId: env.get('GITHUB_CLIENT_ID'),
31
+ * clientSecret: env.get('GITHUB_CLIENT_SECRET'),
32
+ * callbackUrl: 'http://localhost:3333/github/callback'
33
+ * }),
34
+ * google: services.google({
35
+ * clientId: env.get('GOOGLE_CLIENT_ID'),
36
+ * clientSecret: env.get('GOOGLE_CLIENT_SECRET'),
37
+ * callbackUrl: 'http://localhost:3333/google/callback'
38
+ * })
39
+ * })
40
+ * ```
21
41
  */
22
42
  export declare function defineConfig<KnownSocialProviders extends Record<string, AllyManagerDriverFactory | ConfigProvider<AllyManagerDriverFactory>>>(config: KnownSocialProviders): ConfigProvider<ResolvedConfig<KnownSocialProviders>>;
23
43
  /**
24
- * Helpers to configure social auth services
44
+ * Pre-configured helpers for setting up built-in social authentication
45
+ * providers. Each method accepts provider-specific configuration and
46
+ * returns a config provider that lazily loads and instantiates the driver.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * export default defineConfig({
51
+ * github: services.github({
52
+ * clientId: env.get('GITHUB_CLIENT_ID'),
53
+ * clientSecret: env.get('GITHUB_CLIENT_SECRET'),
54
+ * callbackUrl: 'http://localhost:3333/github/callback',
55
+ * scopes: ['user', 'user:email']
56
+ * })
57
+ * })
58
+ * ```
25
59
  */
26
60
  export declare const services: {
27
61
  discord: (config: DiscordDriverConfig) => ConfigProvider<(ctx: HttpContext) => DiscordDriver>;