@adonisjs/ally 6.0.0 → 6.1.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.
- package/README.md +2 -2
- package/build/{chunk-WM3V3APX.js → chunk-46TOMXWK.js} +92 -15
- package/build/chunk-6BP2DK5A.js +43 -0
- package/build/{chunk-KSJ4CFTC.js → chunk-NK6X76EQ.js} +16 -25
- package/build/{chunk-KWRXS6EG.js → chunk-SBQAXPUK.js} +33 -3
- package/build/chunk-TFPW7D75.js +125 -0
- package/build/index.js +67 -6
- package/build/providers/ally_provider.d.ts +10 -0
- package/build/providers/ally_provider.js +13 -2
- package/build/src/abstract_drivers/oauth1.d.ts +26 -0
- package/build/src/abstract_drivers/oauth2.d.ts +50 -2
- package/build/src/ally_manager.d.ts +67 -3
- package/build/src/define_config.d.ts +16 -1
- package/build/src/drivers/discord.d.ts +9 -0
- package/build/src/drivers/discord.js +13 -3
- package/build/src/drivers/facebook.d.ts +9 -0
- package/build/src/drivers/facebook.js +13 -3
- package/build/src/drivers/github.d.ts +12 -0
- package/build/src/drivers/github.js +17 -4
- package/build/src/drivers/google.d.ts +9 -0
- package/build/src/drivers/google.js +13 -3
- package/build/src/drivers/linked_in.d.ts +12 -0
- package/build/src/drivers/linked_in.js +16 -3
- package/build/src/drivers/linked_in_openid_connect.d.ts +14 -5
- package/build/src/drivers/linked_in_openid_connect.js +14 -5
- package/build/src/drivers/spotify.d.ts +11 -0
- package/build/src/drivers/spotify.js +15 -3
- package/build/src/drivers/twitter.d.ts +17 -0
- package/build/src/drivers/twitter.js +22 -3
- package/build/src/drivers/twitter_x.d.ts +137 -0
- package/build/src/drivers/twitter_x.js +169 -0
- package/build/src/errors.d.ts +29 -0
- package/build/src/redirect_request.d.ts +7 -0
- package/build/src/types.d.ts +150 -0
- package/package.json +8 -8
- package/build/chunk-MLKGABMK.js +0 -9
- package/build/chunk-SZ4YJCVU.js +0 -46
package/build/index.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Oauth1Driver
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SBQAXPUK.js";
|
|
4
4
|
import {
|
|
5
5
|
AllyManager
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TFPW7D75.js";
|
|
7
7
|
import {
|
|
8
8
|
Oauth2Driver
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-46TOMXWK.js";
|
|
10
|
+
import {
|
|
11
|
+
RedirectRequest
|
|
12
|
+
} from "./chunk-NK6X76EQ.js";
|
|
10
13
|
import {
|
|
11
|
-
RedirectRequest,
|
|
12
14
|
errors_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-MLKGABMK.js";
|
|
15
|
+
} from "./chunk-6BP2DK5A.js";
|
|
15
16
|
|
|
16
17
|
// index.ts
|
|
17
18
|
import { HttpClient } from "@poppinss/oauth-client";
|
|
@@ -94,53 +95,113 @@ function defineConfig(config) {
|
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
var services = {
|
|
98
|
+
/**
|
|
99
|
+
* Create a config provider for the Discord OAuth2 driver.
|
|
100
|
+
*
|
|
101
|
+
* @param config - Discord driver configuration.
|
|
102
|
+
* @returns A lazily resolved config provider for the Discord driver.
|
|
103
|
+
*/
|
|
97
104
|
discord(config) {
|
|
98
105
|
return configProvider.create(async () => {
|
|
99
106
|
const { DiscordDriver } = await import("./src/drivers/discord.js");
|
|
100
107
|
return (ctx) => new DiscordDriver(ctx, config);
|
|
101
108
|
});
|
|
102
109
|
},
|
|
110
|
+
/**
|
|
111
|
+
* Create a config provider for the Facebook OAuth2 driver.
|
|
112
|
+
*
|
|
113
|
+
* @param config - Facebook driver configuration.
|
|
114
|
+
* @returns A lazily resolved config provider for the Facebook driver.
|
|
115
|
+
*/
|
|
103
116
|
facebook(config) {
|
|
104
117
|
return configProvider.create(async () => {
|
|
105
118
|
const { FacebookDriver } = await import("./src/drivers/facebook.js");
|
|
106
119
|
return (ctx) => new FacebookDriver(ctx, config);
|
|
107
120
|
});
|
|
108
121
|
},
|
|
122
|
+
/**
|
|
123
|
+
* Create a config provider for the GitHub OAuth2 driver.
|
|
124
|
+
*
|
|
125
|
+
* @param config - GitHub driver configuration.
|
|
126
|
+
* @returns A lazily resolved config provider for the GitHub driver.
|
|
127
|
+
*/
|
|
109
128
|
github(config) {
|
|
110
129
|
return configProvider.create(async () => {
|
|
111
130
|
const { GithubDriver } = await import("./src/drivers/github.js");
|
|
112
131
|
return (ctx) => new GithubDriver(ctx, config);
|
|
113
132
|
});
|
|
114
133
|
},
|
|
134
|
+
/**
|
|
135
|
+
* Create a config provider for the Google OAuth2 driver.
|
|
136
|
+
*
|
|
137
|
+
* @param config - Google driver configuration.
|
|
138
|
+
* @returns A lazily resolved config provider for the Google driver.
|
|
139
|
+
*/
|
|
115
140
|
google(config) {
|
|
116
141
|
return configProvider.create(async () => {
|
|
117
142
|
const { GoogleDriver } = await import("./src/drivers/google.js");
|
|
118
143
|
return (ctx) => new GoogleDriver(ctx, config);
|
|
119
144
|
});
|
|
120
145
|
},
|
|
146
|
+
/**
|
|
147
|
+
* Create a config provider for the LinkedIn OAuth2 driver.
|
|
148
|
+
*
|
|
149
|
+
* @param config - LinkedIn driver configuration.
|
|
150
|
+
* @returns A lazily resolved config provider for the LinkedIn driver.
|
|
151
|
+
*/
|
|
121
152
|
linkedin(config) {
|
|
122
153
|
return configProvider.create(async () => {
|
|
123
154
|
const { LinkedInDriver } = await import("./src/drivers/linked_in.js");
|
|
124
155
|
return (ctx) => new LinkedInDriver(ctx, config);
|
|
125
156
|
});
|
|
126
157
|
},
|
|
158
|
+
/**
|
|
159
|
+
* Create a config provider for the LinkedIn OpenID Connect driver.
|
|
160
|
+
*
|
|
161
|
+
* @param config - LinkedIn OpenID Connect driver configuration.
|
|
162
|
+
* @returns A lazily resolved config provider for the LinkedIn OpenID Connect driver.
|
|
163
|
+
*/
|
|
127
164
|
linkedinOpenidConnect(config) {
|
|
128
165
|
return configProvider.create(async () => {
|
|
129
166
|
const { LinkedInOpenidConnectDriver } = await import("./src/drivers/linked_in_openid_connect.js");
|
|
130
167
|
return (ctx) => new LinkedInOpenidConnectDriver(ctx, config);
|
|
131
168
|
});
|
|
132
169
|
},
|
|
170
|
+
/**
|
|
171
|
+
* Create a config provider for the Spotify OAuth2 driver.
|
|
172
|
+
*
|
|
173
|
+
* @param config - Spotify driver configuration.
|
|
174
|
+
* @returns A lazily resolved config provider for the Spotify driver.
|
|
175
|
+
*/
|
|
133
176
|
spotify(config) {
|
|
134
177
|
return configProvider.create(async () => {
|
|
135
178
|
const { SpotifyDriver } = await import("./src/drivers/spotify.js");
|
|
136
179
|
return (ctx) => new SpotifyDriver(ctx, config);
|
|
137
180
|
});
|
|
138
181
|
},
|
|
182
|
+
/**
|
|
183
|
+
* Create a config provider for the Twitter OAuth1 driver.
|
|
184
|
+
*
|
|
185
|
+
* @param config - Twitter driver configuration.
|
|
186
|
+
* @returns A lazily resolved config provider for the Twitter driver.
|
|
187
|
+
*/
|
|
139
188
|
twitter(config) {
|
|
140
189
|
return configProvider.create(async () => {
|
|
141
190
|
const { TwitterDriver } = await import("./src/drivers/twitter.js");
|
|
142
191
|
return (ctx) => new TwitterDriver(ctx, config);
|
|
143
192
|
});
|
|
193
|
+
},
|
|
194
|
+
/**
|
|
195
|
+
* Create a config provider for the X OAuth2 driver.
|
|
196
|
+
*
|
|
197
|
+
* @param config - X driver configuration.
|
|
198
|
+
* @returns A lazily resolved config provider for the X driver.
|
|
199
|
+
*/
|
|
200
|
+
twitterX(config) {
|
|
201
|
+
return configProvider.create(async () => {
|
|
202
|
+
const { TwitterXDriver } = await import("./src/drivers/twitter_x.js");
|
|
203
|
+
return (ctx) => new TwitterXDriver(ctx, config);
|
|
204
|
+
});
|
|
144
205
|
}
|
|
145
206
|
};
|
|
146
207
|
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-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-TFPW7D75.js";
|
|
4
|
+
import "../chunk-6BP2DK5A.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.
|
|
124
|
-
*
|
|
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
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import type { AllyManagerDriverFactory } from './types.ts';
|
|
2
|
+
import type { AllyManagerDriverFactory, AllyManagerUseOptions } from './types.ts';
|
|
3
3
|
/**
|
|
4
4
|
* AllyManager is used to create and manage social authentication driver
|
|
5
5
|
* instances during an HTTP request. The drivers are cached during the
|
|
@@ -20,23 +20,87 @@ import type { AllyManagerDriverFactory } from './types.ts';
|
|
|
20
20
|
*/
|
|
21
21
|
export declare class AllyManager<KnownSocialProviders extends Record<string, AllyManagerDriverFactory>> {
|
|
22
22
|
#private;
|
|
23
|
+
/**
|
|
24
|
+
* The configured provider factories available for the current application.
|
|
25
|
+
*/
|
|
23
26
|
config: KnownSocialProviders;
|
|
24
27
|
/**
|
|
28
|
+
* Create a new Ally manager for the current request.
|
|
29
|
+
*
|
|
25
30
|
* @param config - Map of provider names to driver factory functions
|
|
26
31
|
* @param ctx - The current HTTP context
|
|
27
32
|
*/
|
|
28
|
-
constructor(
|
|
33
|
+
constructor(
|
|
34
|
+
/**
|
|
35
|
+
* The configured provider factories available for the current application.
|
|
36
|
+
*/
|
|
37
|
+
config: KnownSocialProviders, ctx: HttpContext);
|
|
38
|
+
/**
|
|
39
|
+
* Find if a provider has been configured.
|
|
40
|
+
*
|
|
41
|
+
* @param provider - The provider name to check.
|
|
42
|
+
* @returns `true` when the provider exists in the manager config.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* if (ally.has(provider)) {
|
|
47
|
+
* await ally.use(provider).redirect()
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
has(provider: string): provider is Extract<keyof KnownSocialProviders, string>;
|
|
52
|
+
/**
|
|
53
|
+
* Find if a provider allows local signup.
|
|
54
|
+
*
|
|
55
|
+
* @param provider - The configured provider name to inspect.
|
|
56
|
+
* @returns `true` when the provider does not opt out of local signup.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* if (ally.allowsLocalSignup('github')) {
|
|
61
|
+
* return ally.use('github', { intent: 'signup' }).redirect()
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
allowsLocalSignup(provider: keyof KnownSocialProviders & string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Returns configured provider names.
|
|
68
|
+
*
|
|
69
|
+
* @returns An array of configured provider names.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const providers = ally.configuredProviderNames()
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
configuredProviderNames(): Array<Extract<keyof KnownSocialProviders, string>>;
|
|
77
|
+
/**
|
|
78
|
+
* Returns provider names that allow local signup.
|
|
79
|
+
*
|
|
80
|
+
* @returns An array of configured provider names that allow signup flows.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const signupProviders = ally.signupProviderNames()
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
signupProviderNames(): Array<Extract<keyof KnownSocialProviders, string>>;
|
|
29
88
|
/**
|
|
30
89
|
* Get a driver instance for the specified social provider. The driver
|
|
31
90
|
* instance is cached for the duration of the HTTP request.
|
|
32
91
|
*
|
|
33
92
|
* @param provider - The name of the social provider (e.g., 'github', 'google')
|
|
93
|
+
* @param options - Additional options used to qualify the provider usage.
|
|
94
|
+
* @returns The instantiated social authentication driver.
|
|
34
95
|
*
|
|
35
96
|
* @example
|
|
36
97
|
* ```ts
|
|
37
98
|
* const github = ally.use('github')
|
|
38
99
|
* await github.redirect()
|
|
100
|
+
*
|
|
101
|
+
* const signupDriver = ally.use('github', { intent: 'signup' })
|
|
102
|
+
* await signupDriver.redirect()
|
|
39
103
|
* ```
|
|
40
104
|
*/
|
|
41
|
-
use<SocialProvider extends keyof KnownSocialProviders>(provider: SocialProvider): ReturnType<KnownSocialProviders[SocialProvider]>;
|
|
105
|
+
use<SocialProvider extends keyof KnownSocialProviders>(provider: SocialProvider, options?: AllyManagerUseOptions): ReturnType<KnownSocialProviders[SocialProvider]>;
|
|
42
106
|
}
|
|
@@ -4,14 +4,17 @@ import type { GoogleDriver } from './drivers/google.ts';
|
|
|
4
4
|
import type { GithubDriver } from './drivers/github.ts';
|
|
5
5
|
import type { SpotifyDriver } from './drivers/spotify.ts';
|
|
6
6
|
import type { TwitterDriver } from './drivers/twitter.ts';
|
|
7
|
+
import type { TwitterXDriver } from './drivers/twitter_x.ts';
|
|
7
8
|
import type { DiscordDriver } from './drivers/discord.ts';
|
|
8
9
|
import type { FacebookDriver } from './drivers/facebook.ts';
|
|
9
10
|
import type { LinkedInDriver } from './drivers/linked_in.ts';
|
|
10
11
|
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
|
+
import type { GoogleDriverConfig, GithubDriverConfig, SpotifyDriverConfig, DiscordDriverConfig, TwitterDriverConfig, TwitterXDriverConfig, LinkedInDriverConfig, LinkedInOpenidConnectDriverConfig, FacebookDriverConfig, AllyManagerDriverFactory } from './types.ts';
|
|
12
13
|
/**
|
|
13
14
|
* Shape of config after it has been resolved from
|
|
14
15
|
* the config provider
|
|
16
|
+
*
|
|
17
|
+
* Maps config providers to their resolved driver factory values.
|
|
15
18
|
*/
|
|
16
19
|
type ResolvedConfig<KnownSocialProviders extends Record<string, AllyManagerDriverFactory | ConfigProvider<AllyManagerDriverFactory>>> = {
|
|
17
20
|
[K in keyof KnownSocialProviders]: KnownSocialProviders[K] extends ConfigProvider<infer A> ? A : KnownSocialProviders[K];
|
|
@@ -22,6 +25,7 @@ type ResolvedConfig<KnownSocialProviders extends Record<string, AllyManagerDrive
|
|
|
22
25
|
* functions or config providers.
|
|
23
26
|
*
|
|
24
27
|
* @param config - An object mapping provider names to driver factories
|
|
28
|
+
* @returns A config provider that resolves all registered providers.
|
|
25
29
|
*
|
|
26
30
|
* @example
|
|
27
31
|
* ```ts
|
|
@@ -47,6 +51,16 @@ export declare function defineConfig<KnownSocialProviders extends Record<string,
|
|
|
47
51
|
*
|
|
48
52
|
* @example
|
|
49
53
|
* ```ts
|
|
54
|
+
* const github = services.github({
|
|
55
|
+
* clientId: env.get('GITHUB_CLIENT_ID'),
|
|
56
|
+
* clientSecret: env.get('GITHUB_CLIENT_SECRET'),
|
|
57
|
+
* callbackUrl: 'http://localhost:3333/github/callback',
|
|
58
|
+
* disallowLocalSignup: true,
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
50
64
|
* export default defineConfig({
|
|
51
65
|
* github: services.github({
|
|
52
66
|
* clientId: env.get('GITHUB_CLIENT_ID'),
|
|
@@ -66,5 +80,6 @@ export declare const services: {
|
|
|
66
80
|
linkedinOpenidConnect: (config: LinkedInOpenidConnectDriverConfig) => ConfigProvider<(ctx: HttpContext) => LinkedInOpenidConnectDriver>;
|
|
67
81
|
spotify: (config: SpotifyDriverConfig) => ConfigProvider<(ctx: HttpContext) => SpotifyDriver>;
|
|
68
82
|
twitter: (config: TwitterDriverConfig) => ConfigProvider<(ctx: HttpContext) => TwitterDriver>;
|
|
83
|
+
twitterX: (config: TwitterXDriverConfig) => ConfigProvider<(ctx: HttpContext) => TwitterXDriver>;
|
|
69
84
|
};
|
|
70
85
|
export {};
|
|
@@ -36,8 +36,17 @@ import { Oauth2Driver } from '../abstract_drivers/oauth2.ts';
|
|
|
36
36
|
*/
|
|
37
37
|
export declare class DiscordDriver extends Oauth2Driver<DiscordToken, DiscordScopes> {
|
|
38
38
|
config: DiscordDriverConfig;
|
|
39
|
+
/**
|
|
40
|
+
* Discord token endpoint URL.
|
|
41
|
+
*/
|
|
39
42
|
protected accessTokenUrl: string;
|
|
43
|
+
/**
|
|
44
|
+
* Discord authorization endpoint URL.
|
|
45
|
+
*/
|
|
40
46
|
protected authorizeUrl: string;
|
|
47
|
+
/**
|
|
48
|
+
* Discord user profile endpoint URL.
|
|
49
|
+
*/
|
|
41
50
|
protected userInfoUrl: string;
|
|
42
51
|
/**
|
|
43
52
|
* The param name for the authorization code
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Oauth2Driver
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
5
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-46TOMXWK.js";
|
|
4
|
+
import "../../chunk-NK6X76EQ.js";
|
|
5
|
+
import "../../chunk-6BP2DK5A.js";
|
|
6
6
|
|
|
7
7
|
// src/drivers/discord.ts
|
|
8
8
|
var DiscordDriver = class extends Oauth2Driver {
|
|
@@ -15,8 +15,18 @@ var DiscordDriver = class extends Oauth2Driver {
|
|
|
15
15
|
this.config = config;
|
|
16
16
|
this.loadState();
|
|
17
17
|
}
|
|
18
|
+
config;
|
|
19
|
+
/**
|
|
20
|
+
* Discord token endpoint URL.
|
|
21
|
+
*/
|
|
18
22
|
accessTokenUrl = "https://discord.com/api/oauth2/token";
|
|
23
|
+
/**
|
|
24
|
+
* Discord authorization endpoint URL.
|
|
25
|
+
*/
|
|
19
26
|
authorizeUrl = "https://discord.com/oauth2/authorize";
|
|
27
|
+
/**
|
|
28
|
+
* Discord user profile endpoint URL.
|
|
29
|
+
*/
|
|
20
30
|
userInfoUrl = "https://discord.com/api/users/@me";
|
|
21
31
|
/**
|
|
22
32
|
* The param name for the authorization code
|
|
@@ -36,8 +36,17 @@ import { Oauth2Driver } from '../abstract_drivers/oauth2.ts';
|
|
|
36
36
|
*/
|
|
37
37
|
export declare class FacebookDriver extends Oauth2Driver<FacebookToken, FacebookScopes> {
|
|
38
38
|
config: FacebookDriverConfig;
|
|
39
|
+
/**
|
|
40
|
+
* Facebook token endpoint URL.
|
|
41
|
+
*/
|
|
39
42
|
protected accessTokenUrl: string;
|
|
43
|
+
/**
|
|
44
|
+
* Facebook authorization endpoint URL.
|
|
45
|
+
*/
|
|
40
46
|
protected authorizeUrl: string;
|
|
47
|
+
/**
|
|
48
|
+
* Facebook profile endpoint URL.
|
|
49
|
+
*/
|
|
41
50
|
protected userInfoUrl: string;
|
|
42
51
|
/**
|
|
43
52
|
* The default set of fields to query for the user request
|