@adonisjs/ally 6.0.0 → 6.2.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 (37) hide show
  1. package/README.md +2 -2
  2. package/build/{chunk-KWRXS6EG.js → chunk-4QTU45GZ.js} +33 -3
  3. package/build/{chunk-WM3V3APX.js → chunk-7V2EH7U6.js} +92 -15
  4. package/build/chunk-ISWHUP4Q.js +125 -0
  5. package/build/{chunk-KSJ4CFTC.js → chunk-NK6X76EQ.js} +16 -25
  6. package/build/chunk-TSIMPJ6I.js +119 -0
  7. package/build/index.js +90 -21
  8. package/build/providers/ally_provider.d.ts +10 -0
  9. package/build/providers/ally_provider.js +13 -2
  10. package/build/src/abstract_drivers/oauth1.d.ts +26 -0
  11. package/build/src/abstract_drivers/oauth2.d.ts +50 -2
  12. package/build/src/ally_manager.d.ts +67 -3
  13. package/build/src/define_config.d.ts +16 -1
  14. package/build/src/drivers/discord.d.ts +9 -0
  15. package/build/src/drivers/discord.js +13 -3
  16. package/build/src/drivers/facebook.d.ts +9 -0
  17. package/build/src/drivers/facebook.js +13 -3
  18. package/build/src/drivers/github.d.ts +12 -0
  19. package/build/src/drivers/github.js +17 -4
  20. package/build/src/drivers/google.d.ts +9 -0
  21. package/build/src/drivers/google.js +13 -3
  22. package/build/src/drivers/linked_in.d.ts +12 -0
  23. package/build/src/drivers/linked_in.js +16 -3
  24. package/build/src/drivers/linked_in_openid_connect.d.ts +14 -5
  25. package/build/src/drivers/linked_in_openid_connect.js +14 -5
  26. package/build/src/drivers/spotify.d.ts +11 -0
  27. package/build/src/drivers/spotify.js +15 -3
  28. package/build/src/drivers/twitter.d.ts +17 -0
  29. package/build/src/drivers/twitter.js +22 -3
  30. package/build/src/drivers/twitter_x.d.ts +137 -0
  31. package/build/src/drivers/twitter_x.js +169 -0
  32. package/build/src/errors.d.ts +190 -2
  33. package/build/src/redirect_request.d.ts +7 -0
  34. package/build/src/types.d.ts +150 -0
  35. package/package.json +19 -9
  36. package/build/chunk-MLKGABMK.js +0 -9
  37. package/build/chunk-SZ4YJCVU.js +0 -46
@@ -0,0 +1,119 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/errors.ts
8
+ var errors_exports = {};
9
+ __export(errors_exports, {
10
+ E_LOCAL_SIGNUP_DISALLOWED: () => E_LOCAL_SIGNUP_DISALLOWED,
11
+ E_OAUTH_MISSING_CODE: () => E_OAUTH_MISSING_CODE,
12
+ E_OAUTH_STATE_MISMATCH: () => E_OAUTH_STATE_MISMATCH,
13
+ E_UNKNOWN_ALLY_PROVIDER: () => E_UNKNOWN_ALLY_PROVIDER,
14
+ HttpResponseException: () => HttpResponseException
15
+ });
16
+ import { Exception } from "@adonisjs/core/exceptions";
17
+ var HttpResponseException = class extends Exception {
18
+ /**
19
+ * Returns the message to be sent in the HTTP response.
20
+ * Feel free to override this method and return a custom
21
+ * response.
22
+ */
23
+ getResponseMessage(error, ctx) {
24
+ if ("i18n" in ctx) {
25
+ return ctx.i18n.t(error.identifier, {}, error.message);
26
+ }
27
+ return error.message;
28
+ }
29
+ /**
30
+ * Converts exception to an HTTP response
31
+ */
32
+ async handle(error, ctx) {
33
+ const message = this.getResponseMessage(error, ctx);
34
+ switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
35
+ case "html":
36
+ case null:
37
+ if (ctx.session) {
38
+ ctx.session.flash("error", message);
39
+ ctx.session.flashErrors({ [error.code]: message });
40
+ ctx.response.redirect().back();
41
+ } else {
42
+ ctx.response.status(error.status).send(message);
43
+ }
44
+ break;
45
+ case "json":
46
+ ctx.response.status(error.status).send({
47
+ errors: [
48
+ {
49
+ message
50
+ }
51
+ ]
52
+ });
53
+ break;
54
+ case "application/vnd.api+json":
55
+ ctx.response.status(error.status).send({
56
+ errors: [
57
+ {
58
+ code: error.code,
59
+ title: message
60
+ }
61
+ ]
62
+ });
63
+ break;
64
+ }
65
+ }
66
+ };
67
+ var E_OAUTH_MISSING_CODE = class extends HttpResponseException {
68
+ static status = 500;
69
+ static code = "E_OAUTH_MISSING_CODE";
70
+ /**
71
+ * Translation identifier. Can be customized
72
+ */
73
+ identifier = "errors.E_OAUTH_MISSING_CODE";
74
+ constructor(args, options) {
75
+ super(
76
+ `Cannot request access token. Redirect request is missing the "${args[0]}" param`,
77
+ options
78
+ );
79
+ }
80
+ };
81
+ var E_OAUTH_STATE_MISMATCH = class extends HttpResponseException {
82
+ static status = 400;
83
+ static code = "E_OAUTH_STATE_MISMATCH";
84
+ static message = "Unable to verify re-redirect state";
85
+ /**
86
+ * Translation identifier. Can be customized
87
+ */
88
+ identifier = "errors.E_OAUTH_STATE_MISMATCH";
89
+ };
90
+ var E_UNKNOWN_ALLY_PROVIDER = class extends HttpResponseException {
91
+ static status = 404;
92
+ static code = "E_UNKNOWN_ALLY_PROVIDER";
93
+ /**
94
+ * Translation identifier. Can be customized
95
+ */
96
+ identifier = "errors.E_UNKNOWN_ALLY_PROVIDER";
97
+ constructor(args, options) {
98
+ super(`Unknown authentication provider "${args[0]}"`, options);
99
+ }
100
+ };
101
+ var E_LOCAL_SIGNUP_DISALLOWED = class extends HttpResponseException {
102
+ static status = 403;
103
+ static code = "E_LOCAL_SIGNUP_DISALLOWED";
104
+ /**
105
+ * Translation identifier. Can be customized
106
+ */
107
+ identifier = "errors.E_LOCAL_SIGNUP_DISALLOWED";
108
+ constructor(args, options) {
109
+ super(`Cannot signup using "${args[0]}". Local signup is disabled for this provider`, options);
110
+ }
111
+ };
112
+
113
+ export {
114
+ E_OAUTH_MISSING_CODE,
115
+ E_OAUTH_STATE_MISMATCH,
116
+ E_UNKNOWN_ALLY_PROVIDER,
117
+ E_LOCAL_SIGNUP_DISALLOWED,
118
+ errors_exports
119
+ };
package/build/index.js CHANGED
@@ -1,17 +1,18 @@
1
1
  import {
2
2
  Oauth1Driver
3
- } from "./chunk-KWRXS6EG.js";
3
+ } from "./chunk-4QTU45GZ.js";
4
4
  import {
5
5
  AllyManager
6
- } from "./chunk-SZ4YJCVU.js";
6
+ } from "./chunk-ISWHUP4Q.js";
7
7
  import {
8
8
  Oauth2Driver
9
- } from "./chunk-WM3V3APX.js";
9
+ } from "./chunk-7V2EH7U6.js";
10
+ import {
11
+ RedirectRequest
12
+ } from "./chunk-NK6X76EQ.js";
10
13
  import {
11
- RedirectRequest,
12
14
  errors_exports
13
- } from "./chunk-KSJ4CFTC.js";
14
- import "./chunk-MLKGABMK.js";
15
+ } from "./chunk-TSIMPJ6I.js";
15
16
 
16
17
  // index.ts
17
18
  import { HttpClient } from "@poppinss/oauth-client";
@@ -21,14 +22,19 @@ var stubsRoot = import.meta.dirname;
21
22
 
22
23
  // configure.ts
23
24
  var AVAILABLE_PROVIDERS = [
24
- "discord",
25
- "facebook",
26
- "github",
27
- "google",
28
- "linkedin",
29
- "linkedinOpenidConnect",
30
- "spotify",
31
- "twitter"
25
+ { name: "discord", message: "Discord", envPrefix: "DISCORD" },
26
+ { name: "facebook", message: "Facebook", envPrefix: "FACEBOOK" },
27
+ { name: "github", message: "GitHub", envPrefix: "GITHUB" },
28
+ { name: "google", message: "Google", envPrefix: "GOOGLE" },
29
+ { name: "linkedin", message: "LinkedIn", envPrefix: "LINKEDIN" },
30
+ {
31
+ name: "linkedinOpenidConnect",
32
+ message: "LinkedIn (OpenID Connect)",
33
+ envPrefix: "LINKEDIN_OC"
34
+ },
35
+ { name: "spotify", message: "Spotify", envPrefix: "SPOTIFY" },
36
+ { name: "twitter", message: "Twitter", envPrefix: "TWITTER" },
37
+ { name: "twitterX", message: "Twitter X (OAuth2)", envPrefix: "TWITTER_X" }
32
38
  ];
33
39
  async function configure(command) {
34
40
  let selectedProviders = command.parsedFlags.providers;
@@ -43,17 +49,20 @@ async function configure(command) {
43
49
  }
44
50
  );
45
51
  }
46
- let providers = typeof selectedProviders === "string" ? [selectedProviders] : selectedProviders;
47
- const unknownProvider = providers.find((provider) => !AVAILABLE_PROVIDERS.includes(provider));
52
+ const providerNames = typeof selectedProviders === "string" ? [selectedProviders] : selectedProviders;
53
+ const unknownProvider = providerNames.find(
54
+ (name) => !AVAILABLE_PROVIDERS.some((p) => p.name === name)
55
+ );
48
56
  if (unknownProvider) {
49
57
  command.exitCode = 1;
50
58
  command.logger.error(`Invalid social provider "${unknownProvider}"`);
51
59
  return;
52
60
  }
61
+ const providers = providerNames.map((name) => AVAILABLE_PROVIDERS.find((p) => p.name === name));
53
62
  const codemods = await command.createCodemods();
54
63
  await codemods.makeUsingStub(stubsRoot, "config/ally.stub", {
55
64
  providers: providers.map((provider) => {
56
- return { provider, envPrefix: provider.toUpperCase() };
65
+ return { provider: provider.name, envPrefix: provider.envPrefix };
57
66
  })
58
67
  });
59
68
  await codemods.updateRcFile((rcFile) => {
@@ -61,15 +70,15 @@ async function configure(command) {
61
70
  });
62
71
  await codemods.defineEnvVariables(
63
72
  providers.reduce((result, provider) => {
64
- result[`${provider.toUpperCase()}_CLIENT_ID`] = "";
65
- result[`${provider.toUpperCase()}_CLIENT_SECRET`] = "";
73
+ result[`${provider.envPrefix}_CLIENT_ID`] = "";
74
+ result[`${provider.envPrefix}_CLIENT_SECRET`] = "";
66
75
  return result;
67
76
  }, {})
68
77
  );
69
78
  await codemods.defineEnvValidations({
70
79
  variables: providers.reduce((result, provider) => {
71
- result[`${provider.toUpperCase()}_CLIENT_ID`] = "Env.schema.string()";
72
- result[`${provider.toUpperCase()}_CLIENT_SECRET`] = "Env.schema.string()";
80
+ result[`${provider.envPrefix}_CLIENT_ID`] = "Env.schema.string()";
81
+ result[`${provider.envPrefix}_CLIENT_SECRET`] = "Env.schema.string()";
73
82
  return result;
74
83
  }, {}),
75
84
  leadingComment: "Variables for configuring ally package"
@@ -94,53 +103,113 @@ function defineConfig(config) {
94
103
  });
95
104
  }
96
105
  var services = {
106
+ /**
107
+ * Create a config provider for the Discord OAuth2 driver.
108
+ *
109
+ * @param config - Discord driver configuration.
110
+ * @returns A lazily resolved config provider for the Discord driver.
111
+ */
97
112
  discord(config) {
98
113
  return configProvider.create(async () => {
99
114
  const { DiscordDriver } = await import("./src/drivers/discord.js");
100
115
  return (ctx) => new DiscordDriver(ctx, config);
101
116
  });
102
117
  },
118
+ /**
119
+ * Create a config provider for the Facebook OAuth2 driver.
120
+ *
121
+ * @param config - Facebook driver configuration.
122
+ * @returns A lazily resolved config provider for the Facebook driver.
123
+ */
103
124
  facebook(config) {
104
125
  return configProvider.create(async () => {
105
126
  const { FacebookDriver } = await import("./src/drivers/facebook.js");
106
127
  return (ctx) => new FacebookDriver(ctx, config);
107
128
  });
108
129
  },
130
+ /**
131
+ * Create a config provider for the GitHub OAuth2 driver.
132
+ *
133
+ * @param config - GitHub driver configuration.
134
+ * @returns A lazily resolved config provider for the GitHub driver.
135
+ */
109
136
  github(config) {
110
137
  return configProvider.create(async () => {
111
138
  const { GithubDriver } = await import("./src/drivers/github.js");
112
139
  return (ctx) => new GithubDriver(ctx, config);
113
140
  });
114
141
  },
142
+ /**
143
+ * Create a config provider for the Google OAuth2 driver.
144
+ *
145
+ * @param config - Google driver configuration.
146
+ * @returns A lazily resolved config provider for the Google driver.
147
+ */
115
148
  google(config) {
116
149
  return configProvider.create(async () => {
117
150
  const { GoogleDriver } = await import("./src/drivers/google.js");
118
151
  return (ctx) => new GoogleDriver(ctx, config);
119
152
  });
120
153
  },
154
+ /**
155
+ * Create a config provider for the LinkedIn OAuth2 driver.
156
+ *
157
+ * @param config - LinkedIn driver configuration.
158
+ * @returns A lazily resolved config provider for the LinkedIn driver.
159
+ */
121
160
  linkedin(config) {
122
161
  return configProvider.create(async () => {
123
162
  const { LinkedInDriver } = await import("./src/drivers/linked_in.js");
124
163
  return (ctx) => new LinkedInDriver(ctx, config);
125
164
  });
126
165
  },
166
+ /**
167
+ * Create a config provider for the LinkedIn OpenID Connect driver.
168
+ *
169
+ * @param config - LinkedIn OpenID Connect driver configuration.
170
+ * @returns A lazily resolved config provider for the LinkedIn OpenID Connect driver.
171
+ */
127
172
  linkedinOpenidConnect(config) {
128
173
  return configProvider.create(async () => {
129
174
  const { LinkedInOpenidConnectDriver } = await import("./src/drivers/linked_in_openid_connect.js");
130
175
  return (ctx) => new LinkedInOpenidConnectDriver(ctx, config);
131
176
  });
132
177
  },
178
+ /**
179
+ * Create a config provider for the Spotify OAuth2 driver.
180
+ *
181
+ * @param config - Spotify driver configuration.
182
+ * @returns A lazily resolved config provider for the Spotify driver.
183
+ */
133
184
  spotify(config) {
134
185
  return configProvider.create(async () => {
135
186
  const { SpotifyDriver } = await import("./src/drivers/spotify.js");
136
187
  return (ctx) => new SpotifyDriver(ctx, config);
137
188
  });
138
189
  },
190
+ /**
191
+ * Create a config provider for the Twitter OAuth1 driver.
192
+ *
193
+ * @param config - Twitter driver configuration.
194
+ * @returns A lazily resolved config provider for the Twitter driver.
195
+ */
139
196
  twitter(config) {
140
197
  return configProvider.create(async () => {
141
198
  const { TwitterDriver } = await import("./src/drivers/twitter.js");
142
199
  return (ctx) => new TwitterDriver(ctx, config);
143
200
  });
201
+ },
202
+ /**
203
+ * Create a config provider for the X OAuth2 driver.
204
+ *
205
+ * @param config - X driver configuration.
206
+ * @returns A lazily resolved config provider for the X driver.
207
+ */
208
+ twitterX(config) {
209
+ return configProvider.create(async () => {
210
+ const { TwitterXDriver } = await import("./src/drivers/twitter_x.js");
211
+ return (ctx) => new TwitterXDriver(ctx, config);
212
+ });
144
213
  }
145
214
  };
146
215
  export {
@@ -10,6 +10,16 @@ declare module '@adonisjs/core/http' {
10
10
  */
11
11
  export default class AllyProvider {
12
12
  protected app: ApplicationService;
13
+ /**
14
+ * Create a new Ally provider instance.
15
+ *
16
+ * @param app - The AdonisJS application service.
17
+ */
13
18
  constructor(app: ApplicationService);
19
+ /**
20
+ * Boot the provider and register the `ctx.ally` getter.
21
+ *
22
+ * @returns A promise that resolves once the provider has been booted.
23
+ */
14
24
  boot(): Promise<void>;
15
25
  }
@@ -1,16 +1,27 @@
1
1
  import {
2
2
  AllyManager
3
- } from "../chunk-SZ4YJCVU.js";
4
- import "../chunk-MLKGABMK.js";
3
+ } from "../chunk-ISWHUP4Q.js";
4
+ import "../chunk-TSIMPJ6I.js";
5
5
 
6
6
  // providers/ally_provider.ts
7
7
  import { configProvider } from "@adonisjs/core";
8
8
  import { HttpContext } from "@adonisjs/core/http";
9
9
  import { RuntimeException } from "@adonisjs/core/exceptions";
10
10
  var AllyProvider = class {
11
+ /**
12
+ * Create a new Ally provider instance.
13
+ *
14
+ * @param app - The AdonisJS application service.
15
+ */
11
16
  constructor(app) {
12
17
  this.app = app;
13
18
  }
19
+ app;
20
+ /**
21
+ * Boot the provider and register the `ctx.ally` getter.
22
+ *
23
+ * @returns A promise that resolves once the provider has been booted.
24
+ */
14
25
  async boot() {
15
26
  const allyConfigProvider = this.app.config.get("ally");
16
27
  const config = await configProvider.resolve(this.app, allyConfigProvider);
@@ -80,6 +80,7 @@ export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scop
80
80
  * authorization from the current request.
81
81
  *
82
82
  * @param callback - Optional callback to customize the API request
83
+ * @returns A promise resolving to the authenticated user profile.
83
84
  */
84
85
  abstract user(callback?: (request: ApiRequestContract) => void): Promise<AllyUserContract<Token>>;
85
86
  /**
@@ -89,6 +90,7 @@ export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scop
89
90
  * @param token - The access token
90
91
  * @param secret - The token secret
91
92
  * @param callback - Optional callback to customize the API request
93
+ * @returns A promise resolving to the authenticated user profile.
92
94
  */
93
95
  abstract userFromTokenAndSecret(token: string, secret: string, callback?: (request: ApiRequestContract) => void): Promise<AllyUserContract<{
94
96
  token: string;
@@ -97,6 +99,8 @@ export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scop
97
99
  /**
98
100
  * Check if the current error indicates that the user denied access.
99
101
  * Different providers use different error codes for access denial.
102
+ *
103
+ * @returns `true` when the provider reported an access-denied state.
100
104
  */
101
105
  abstract accessDenied(): boolean;
102
106
  /**
@@ -111,9 +115,13 @@ export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scop
111
115
  /**
112
116
  * The cookie name for storing the OAuth token secret.
113
117
  * Automatically derived from the token cookie name.
118
+ *
119
+ * @returns The cookie name used to persist the OAuth token secret.
114
120
  */
115
121
  protected get oauthSecretCookieName(): string;
116
122
  /**
123
+ * Create a new OAuth1 driver instance.
124
+ *
117
125
  * @param ctx - The current HTTP context
118
126
  * @param config - OAuth1 driver configuration
119
127
  */
@@ -123,6 +131,7 @@ export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scop
123
131
  * with scope support.
124
132
  *
125
133
  * @param url - The base authorization URL
134
+ * @returns A redirect request builder for the given URL.
126
135
  */
127
136
  protected urlBuilder(url: string): RedirectRequest<string>;
128
137
  /**
@@ -142,6 +151,8 @@ export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scop
142
151
  /**
143
152
  * OAuth1 does not support stateless authentication due to the
144
153
  * three-legged authentication flow requiring token persistence.
154
+ *
155
+ * @returns This method never returns.
145
156
  */
146
157
  stateless(): never;
147
158
  /**
@@ -150,6 +161,7 @@ export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scop
150
161
  * in a different context.
151
162
  *
152
163
  * @param callback - Optional callback to customize the redirect request
164
+ * @returns A promise resolving to the authorization URL.
153
165
  *
154
166
  * @example
155
167
  * ```ts
@@ -162,6 +174,7 @@ export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scop
162
174
  * The request token is automatically obtained and stored in cookies.
163
175
  *
164
176
  * @param callback - Optional callback to customize the redirect request
177
+ * @returns A promise that resolves after the redirect response is prepared.
165
178
  *
166
179
  * @example
167
180
  * ```ts
@@ -172,23 +185,33 @@ export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scop
172
185
  /**
173
186
  * Check if the OAuth token from the callback matches the token
174
187
  * stored in the cookie.
188
+ *
189
+ * @returns `true` when the callback token does not match the stored token.
175
190
  */
176
191
  stateMisMatch(): boolean;
177
192
  /**
178
193
  * Check if an error was returned by the OAuth provider.
194
+ *
195
+ * @returns `true` when an error exists on the callback request.
179
196
  */
180
197
  hasError(): boolean;
181
198
  /**
182
199
  * Get the error code or message returned by the OAuth provider.
183
200
  * Returns 'unknown_error' if no verifier is present and no error was specified.
201
+ *
202
+ * @returns The provider error value when present.
184
203
  */
185
204
  getError(): string | null;
186
205
  /**
187
206
  * Get the OAuth verifier from the callback request.
207
+ *
208
+ * @returns The OAuth verifier when present.
188
209
  */
189
210
  getCode(): string | null;
190
211
  /**
191
212
  * Check if the OAuth verifier is present in the callback request.
213
+ *
214
+ * @returns `true` when the callback request contains an OAuth verifier.
192
215
  */
193
216
  hasCode(): boolean;
194
217
  /**
@@ -197,6 +220,7 @@ export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scop
197
220
  * making the request.
198
221
  *
199
222
  * @param callback - Optional callback to customize the token request
223
+ * @returns A promise resolving to the access token payload.
200
224
  *
201
225
  * @example
202
226
  * ```ts
@@ -206,6 +230,8 @@ export declare abstract class Oauth1Driver<Token extends Oauth1AccessToken, Scop
206
230
  accessToken(callback?: (request: ApiRequestContract) => void): Promise<Token>;
207
231
  /**
208
232
  * Not applicable with OAuth1. Use `userFromTokenAndSecret` instead.
233
+ *
234
+ * @returns This method never returns.
209
235
  */
210
236
  userFromToken(): Promise<never>;
211
237
  }
@@ -39,6 +39,11 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
39
39
  * for your driver to avoid conflicts. For example: `gh_oauth_state`
40
40
  */
41
41
  protected abstract stateCookieName: string;
42
+ /**
43
+ * The cookie name for storing the PKCE code verifier. Define this property
44
+ * in child classes that require PKCE.
45
+ */
46
+ protected codeVerifierCookieName?: string;
42
47
  /**
43
48
  * The query parameter name for sending the state to the OAuth provider.
44
49
  * This is typically 'state' but varies by provider. Check the provider's
@@ -80,6 +85,7 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
80
85
  * authorization code from the current request.
81
86
  *
82
87
  * @param callback - Optional callback to customize the API request
88
+ * @returns A promise resolving to the authenticated user profile.
83
89
  */
84
90
  abstract user(callback?: (request: ApiRequestContract) => void): Promise<AllyUserContract<Token>>;
85
91
  /**
@@ -88,6 +94,7 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
88
94
  *
89
95
  * @param token - The access token
90
96
  * @param callback - Optional callback to customize the API request
97
+ * @returns A promise resolving to the authenticated user profile.
91
98
  */
92
99
  abstract userFromToken(token: string, callback?: (request: ApiRequestContract) => void): Promise<AllyUserContract<{
93
100
  token: string;
@@ -96,6 +103,8 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
96
103
  /**
97
104
  * Check if the current error indicates that the user denied access.
98
105
  * Different providers use different error codes for access denial.
106
+ *
107
+ * @returns `true` when the provider reported an access-denied state.
99
108
  */
100
109
  abstract accessDenied(): boolean;
101
110
  /**
@@ -107,6 +116,13 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
107
116
  */
108
117
  protected stateCookieValue?: string;
109
118
  /**
119
+ * Cached PKCE code verifier value read from the cookie via
120
+ * loadState
121
+ */
122
+ protected codeVerifierCookieValue?: string;
123
+ /**
124
+ * Create a new OAuth2 driver instance.
125
+ *
110
126
  * @param ctx - The current HTTP context
111
127
  * @param config - OAuth2 driver configuration
112
128
  */
@@ -116,12 +132,13 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
116
132
  * with scope support.
117
133
  *
118
134
  * @param url - The base authorization URL
135
+ * @returns A redirect request builder for the given URL.
119
136
  */
120
137
  protected urlBuilder(url: string): RedirectRequest<string>;
121
138
  /**
122
139
  * 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.
140
+ * the cookie. When PKCE is enabled, it also loads the PKCE code verifier.
141
+ * This must be called by child classes in their constructor.
125
142
  *
126
143
  * @example
127
144
  * ```ts
@@ -132,10 +149,26 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
132
149
  * ```
133
150
  */
134
151
  protected loadState(): void;
152
+ /**
153
+ * Returns the PKCE code verifier for building the authorization redirect.
154
+ * This method is expected to create and persist the verifier for later use.
155
+ *
156
+ * @returns The generated PKCE code verifier or `null` when PKCE is disabled.
157
+ */
158
+ protected getPkceCodeVerifierForRedirect(): string | null;
159
+ /**
160
+ * Returns the PKCE code verifier for the access token exchange.
161
+ * This method only reads the verifier that was persisted during redirect.
162
+ *
163
+ * @returns The persisted PKCE code verifier or `null` when PKCE is disabled.
164
+ */
165
+ protected getPkceCodeVerifierForAccessToken(): string | null;
135
166
  /**
136
167
  * Enable stateless authentication by disabling CSRF state verification.
137
168
  * Only use this in scenarios where state verification is not required.
138
169
  *
170
+ * @returns The current driver instance.
171
+ *
139
172
  * @example
140
173
  * ```ts
141
174
  * await ally.use('github').stateless().redirect()
@@ -148,6 +181,7 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
148
181
  * in a different context.
149
182
  *
150
183
  * @param callback - Optional callback to customize the redirect request
184
+ * @returns A promise resolving to the authorization URL.
151
185
  *
152
186
  * @example
153
187
  * ```ts
@@ -162,6 +196,7 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
162
196
  * The state parameter is automatically set for CSRF protection.
163
197
  *
164
198
  * @param callback - Optional callback to customize the redirect request
199
+ * @returns A promise that resolves after the redirect response is prepared.
165
200
  *
166
201
  * @example
167
202
  * ```ts
@@ -175,23 +210,33 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
175
210
  /**
176
211
  * Check if the state parameter from the callback matches the state
177
212
  * stored in the cookie. Returns false in stateless mode.
213
+ *
214
+ * @returns `true` when the state validation fails.
178
215
  */
179
216
  stateMisMatch(): boolean;
180
217
  /**
181
218
  * Check if an error was returned by the OAuth provider.
219
+ *
220
+ * @returns `true` when an error exists on the callback request.
182
221
  */
183
222
  hasError(): boolean;
184
223
  /**
185
224
  * Get the error code or message returned by the OAuth provider.
186
225
  * Returns 'unknown_error' if no code is present and no error was specified.
226
+ *
227
+ * @returns The provider error value when present.
187
228
  */
188
229
  getError(): string | null;
189
230
  /**
190
231
  * Get the authorization code from the callback request.
232
+ *
233
+ * @returns The authorization code when present.
191
234
  */
192
235
  getCode(): string | null;
193
236
  /**
194
237
  * Check if the authorization code is present in the callback request.
238
+ *
239
+ * @returns `true` when the callback request contains an authorization code.
195
240
  */
196
241
  hasCode(): boolean;
197
242
  /**
@@ -199,6 +244,7 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
199
244
  * validates the state and checks for errors before making the request.
200
245
  *
201
246
  * @param callback - Optional callback to customize the token request
247
+ * @returns A promise resolving to the access token payload.
202
248
  *
203
249
  * @example
204
250
  * ```ts
@@ -208,6 +254,8 @@ export declare abstract class Oauth2Driver<Token extends Oauth2AccessToken, Scop
208
254
  accessToken(callback?: (request: ApiRequestContract) => void): Promise<Token>;
209
255
  /**
210
256
  * Not applicable with OAuth2. Use `userFromToken` instead.
257
+ *
258
+ * @returns This method never returns.
211
259
  */
212
260
  userFromTokenAndSecret(): Promise<never>;
213
261
  }