@adonisjs/ally 5.1.1 → 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.
- package/build/{chunk-N72DEJC2.js → chunk-KSJ4CFTC.js} +45 -8
- package/build/{chunk-VHORNQLN.js → chunk-KWRXS6EG.js} +65 -28
- package/build/{chunk-PZ5AY32C.js → chunk-MLKGABMK.js} +0 -1
- package/build/{chunk-NZT2DLWM.js → chunk-SZ4YJCVU.js} +15 -3
- package/build/chunk-WM3V3APX.js +210 -0
- package/build/index.d.ts +8 -8
- package/build/index.js +6 -8
- package/build/providers/ally_provider.d.ts +1 -1
- package/build/providers/ally_provider.js +3 -4
- package/build/src/abstract_drivers/oauth1.d.ts +115 -49
- package/build/src/abstract_drivers/oauth2.d.ts +121 -50
- package/build/src/ally_manager.d.ts +31 -4
- package/build/src/debug.d.ts +9 -0
- package/build/src/define_config.d.ts +45 -11
- package/build/src/drivers/discord.d.ts +76 -11
- package/build/src/drivers/discord.js +47 -12
- package/build/src/drivers/facebook.d.ts +73 -10
- package/build/src/drivers/facebook.js +44 -11
- package/build/src/drivers/github.d.ts +85 -13
- package/build/src/drivers/github.js +56 -14
- package/build/src/drivers/google.d.ts +80 -11
- package/build/src/drivers/google.js +50 -12
- package/build/src/drivers/linked_in.d.ts +76 -10
- package/build/src/drivers/linked_in.js +47 -12
- package/build/src/drivers/linked_in_openid_connect.d.ts +72 -9
- package/build/src/drivers/linked_in_openid_connect.js +42 -10
- package/build/src/drivers/spotify.d.ts +73 -10
- package/build/src/drivers/spotify.js +44 -11
- package/build/src/drivers/twitter.d.ts +65 -8
- package/build/src/drivers/twitter.js +37 -9
- package/build/src/errors.d.ts +10 -2
- package/build/src/redirect_request.d.ts +47 -7
- package/build/src/types.d.ts +1 -1
- package/build/src/types.js +0 -1
- package/package.json +51 -62
- package/build/chunk-GWAQFMNS.js +0 -164
- package/build/chunk-GWAQFMNS.js.map +0 -1
- package/build/chunk-N72DEJC2.js.map +0 -1
- package/build/chunk-NZT2DLWM.js.map +0 -1
- package/build/chunk-PZ5AY32C.js.map +0 -1
- package/build/chunk-VHORNQLN.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/providers/ally_provider.js.map +0 -1
- package/build/src/drivers/discord.js.map +0 -1
- package/build/src/drivers/facebook.js.map +0 -1
- package/build/src/drivers/github.js.map +0 -1
- package/build/src/drivers/google.js.map +0 -1
- package/build/src/drivers/linked_in.js.map +0 -1
- package/build/src/drivers/linked_in_openid_connect.js.map +0 -1
- package/build/src/drivers/spotify.js.map +0 -1
- package/build/src/drivers/twitter.js.map +0 -1
- package/build/src/types.js.map +0 -1
|
@@ -1,9 +1,38 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
2
|
import type { HttpClient } from '@poppinss/oauth-client';
|
|
3
|
-
import type { DiscordScopes, DiscordToken, ApiRequestContract, DiscordDriverConfig, RedirectRequestContract } from '../types.
|
|
4
|
-
import { Oauth2Driver } from '../abstract_drivers/oauth2.
|
|
3
|
+
import type { DiscordScopes, DiscordToken, ApiRequestContract, DiscordDriverConfig, RedirectRequestContract } from '../types.ts';
|
|
4
|
+
import { Oauth2Driver } from '../abstract_drivers/oauth2.ts';
|
|
5
5
|
/**
|
|
6
|
-
* Discord driver
|
|
6
|
+
* Discord OAuth2 driver for authenticating users via Discord.
|
|
7
|
+
* Supports fetching user profile information including username and email.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* router.get('/discord/redirect', ({ ally }) => {
|
|
12
|
+
* return ally.use('discord').redirect((request) => {
|
|
13
|
+
* request.scopes(['identify', 'email', 'guilds'])
|
|
14
|
+
* })
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* router.get('/discord/callback', async ({ ally }) => {
|
|
18
|
+
* const discord = ally.use('discord')
|
|
19
|
+
*
|
|
20
|
+
* if (discord.accessDenied()) {
|
|
21
|
+
* return 'Access was denied'
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* if (discord.stateMisMatch()) {
|
|
25
|
+
* return 'State mismatch error'
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* if (discord.hasError()) {
|
|
29
|
+
* return discord.getError()
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* const user = await discord.user()
|
|
33
|
+
* return user
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
7
36
|
*/
|
|
8
37
|
export declare class DiscordDriver extends Oauth2Driver<DiscordToken, DiscordScopes> {
|
|
9
38
|
config: DiscordDriverConfig;
|
|
@@ -35,22 +64,39 @@ export declare class DiscordDriver extends Oauth2Driver<DiscordToken, DiscordSco
|
|
|
35
64
|
* Scopes separator
|
|
36
65
|
*/
|
|
37
66
|
protected scopesSeparator: string;
|
|
67
|
+
/**
|
|
68
|
+
* @param ctx - The HTTP context
|
|
69
|
+
* @param config - Configuration for the Discord driver
|
|
70
|
+
*/
|
|
38
71
|
constructor(ctx: HttpContext, config: DiscordDriverConfig);
|
|
39
72
|
/**
|
|
40
|
-
*
|
|
73
|
+
* Configures the redirect request with default scopes and Discord-specific
|
|
74
|
+
* parameters like prompt, guild_id, and permissions.
|
|
75
|
+
*
|
|
76
|
+
* @param request - The redirect request to configure
|
|
41
77
|
*/
|
|
42
78
|
protected configureRedirectRequest(request: RedirectRequestContract<DiscordScopes>): void;
|
|
43
79
|
/**
|
|
44
|
-
*
|
|
80
|
+
* Configures the access token request with Discord-specific requirements.
|
|
81
|
+
*
|
|
82
|
+
* @param request - The API request to configure
|
|
45
83
|
*/
|
|
46
84
|
protected configureAccessTokenRequest(request: ApiRequestContract): void;
|
|
47
85
|
/**
|
|
48
|
-
*
|
|
86
|
+
* Creates an authenticated HTTP request with the proper authorization
|
|
87
|
+
* header for Discord API calls.
|
|
88
|
+
*
|
|
89
|
+
* @param url - The API endpoint URL
|
|
90
|
+
* @param token - The access token
|
|
49
91
|
*/
|
|
50
92
|
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
|
|
51
93
|
/**
|
|
52
|
-
* Fetches the user
|
|
53
|
-
*
|
|
94
|
+
* Fetches the authenticated user's profile information from the Discord API.
|
|
95
|
+
*
|
|
96
|
+
* @param token - The access token
|
|
97
|
+
* @param callback - Optional callback to customize the API request
|
|
98
|
+
*
|
|
99
|
+
* @see https://discord.com/developers/docs/resources/user#get-current-user
|
|
54
100
|
*/
|
|
55
101
|
protected getUserInfo(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
|
|
56
102
|
id: any;
|
|
@@ -62,11 +108,21 @@ export declare class DiscordDriver extends Oauth2Driver<DiscordToken, DiscordSco
|
|
|
62
108
|
original: any;
|
|
63
109
|
}>;
|
|
64
110
|
/**
|
|
65
|
-
*
|
|
111
|
+
* Check if the error from the callback indicates that the user
|
|
112
|
+
* denied authorization.
|
|
66
113
|
*/
|
|
67
114
|
accessDenied(): boolean;
|
|
68
115
|
/**
|
|
69
|
-
*
|
|
116
|
+
* Get the authenticated user's profile information using
|
|
117
|
+
* the authorization code from the callback request.
|
|
118
|
+
*
|
|
119
|
+
* @param callback - Optional callback to customize the API request
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* const user = await ally.use('discord').user()
|
|
124
|
+
* console.log(user.name, user.email)
|
|
125
|
+
* ```
|
|
70
126
|
*/
|
|
71
127
|
user(callback?: (request: ApiRequestContract) => void): Promise<{
|
|
72
128
|
token: DiscordToken;
|
|
@@ -79,7 +135,16 @@ export declare class DiscordDriver extends Oauth2Driver<DiscordToken, DiscordSco
|
|
|
79
135
|
original: any;
|
|
80
136
|
}>;
|
|
81
137
|
/**
|
|
82
|
-
*
|
|
138
|
+
* Get the user's profile information using an existing
|
|
139
|
+
* access token.
|
|
140
|
+
*
|
|
141
|
+
* @param token - The Discord access token
|
|
142
|
+
* @param callback - Optional callback to customize the API request
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const user = await ally.use('discord').userFromToken(accessToken)
|
|
147
|
+
* ```
|
|
83
148
|
*/
|
|
84
149
|
userFromToken(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
|
|
85
150
|
token: {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Oauth2Driver
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
5
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-WM3V3APX.js";
|
|
4
|
+
import "../../chunk-KSJ4CFTC.js";
|
|
5
|
+
import "../../chunk-MLKGABMK.js";
|
|
6
6
|
|
|
7
7
|
// src/drivers/discord.ts
|
|
8
8
|
var DiscordDriver = class extends Oauth2Driver {
|
|
9
|
+
/**
|
|
10
|
+
* @param ctx - The HTTP context
|
|
11
|
+
* @param config - Configuration for the Discord driver
|
|
12
|
+
*/
|
|
9
13
|
constructor(ctx, config) {
|
|
10
14
|
super(ctx, config);
|
|
11
15
|
this.config = config;
|
|
@@ -40,7 +44,10 @@ var DiscordDriver = class extends Oauth2Driver {
|
|
|
40
44
|
*/
|
|
41
45
|
scopesSeparator = " ";
|
|
42
46
|
/**
|
|
43
|
-
*
|
|
47
|
+
* Configures the redirect request with default scopes and Discord-specific
|
|
48
|
+
* parameters like prompt, guild_id, and permissions.
|
|
49
|
+
*
|
|
50
|
+
* @param request - The redirect request to configure
|
|
44
51
|
*/
|
|
45
52
|
configureRedirectRequest(request) {
|
|
46
53
|
request.scopes(this.config.scopes || ["identify", "email"]);
|
|
@@ -61,7 +68,9 @@ var DiscordDriver = class extends Oauth2Driver {
|
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
|
-
*
|
|
71
|
+
* Configures the access token request with Discord-specific requirements.
|
|
72
|
+
*
|
|
73
|
+
* @param request - The API request to configure
|
|
65
74
|
*/
|
|
66
75
|
configureAccessTokenRequest(request) {
|
|
67
76
|
if (!this.isStateless) {
|
|
@@ -69,7 +78,11 @@ var DiscordDriver = class extends Oauth2Driver {
|
|
|
69
78
|
}
|
|
70
79
|
}
|
|
71
80
|
/**
|
|
72
|
-
*
|
|
81
|
+
* Creates an authenticated HTTP request with the proper authorization
|
|
82
|
+
* header for Discord API calls.
|
|
83
|
+
*
|
|
84
|
+
* @param url - The API endpoint URL
|
|
85
|
+
* @param token - The access token
|
|
73
86
|
*/
|
|
74
87
|
getAuthenticatedRequest(url, token) {
|
|
75
88
|
const request = this.httpClient(url);
|
|
@@ -79,8 +92,12 @@ var DiscordDriver = class extends Oauth2Driver {
|
|
|
79
92
|
return request;
|
|
80
93
|
}
|
|
81
94
|
/**
|
|
82
|
-
* Fetches the user
|
|
83
|
-
*
|
|
95
|
+
* Fetches the authenticated user's profile information from the Discord API.
|
|
96
|
+
*
|
|
97
|
+
* @param token - The access token
|
|
98
|
+
* @param callback - Optional callback to customize the API request
|
|
99
|
+
*
|
|
100
|
+
* @see https://discord.com/developers/docs/resources/user#get-current-user
|
|
84
101
|
*/
|
|
85
102
|
async getUserInfo(token, callback) {
|
|
86
103
|
const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token);
|
|
@@ -100,7 +117,8 @@ var DiscordDriver = class extends Oauth2Driver {
|
|
|
100
117
|
};
|
|
101
118
|
}
|
|
102
119
|
/**
|
|
103
|
-
*
|
|
120
|
+
* Check if the error from the callback indicates that the user
|
|
121
|
+
* denied authorization.
|
|
104
122
|
*/
|
|
105
123
|
accessDenied() {
|
|
106
124
|
const error = this.getError();
|
|
@@ -110,7 +128,16 @@ var DiscordDriver = class extends Oauth2Driver {
|
|
|
110
128
|
return error === "access_denied";
|
|
111
129
|
}
|
|
112
130
|
/**
|
|
113
|
-
*
|
|
131
|
+
* Get the authenticated user's profile information using
|
|
132
|
+
* the authorization code from the callback request.
|
|
133
|
+
*
|
|
134
|
+
* @param callback - Optional callback to customize the API request
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const user = await ally.use('discord').user()
|
|
139
|
+
* console.log(user.name, user.email)
|
|
140
|
+
* ```
|
|
114
141
|
*/
|
|
115
142
|
async user(callback) {
|
|
116
143
|
const token = await this.accessToken(callback);
|
|
@@ -121,7 +148,16 @@ var DiscordDriver = class extends Oauth2Driver {
|
|
|
121
148
|
};
|
|
122
149
|
}
|
|
123
150
|
/**
|
|
124
|
-
*
|
|
151
|
+
* Get the user's profile information using an existing
|
|
152
|
+
* access token.
|
|
153
|
+
*
|
|
154
|
+
* @param token - The Discord access token
|
|
155
|
+
* @param callback - Optional callback to customize the API request
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* const user = await ally.use('discord').userFromToken(accessToken)
|
|
160
|
+
* ```
|
|
125
161
|
*/
|
|
126
162
|
async userFromToken(token, callback) {
|
|
127
163
|
const user = await this.getUserInfo(token, callback);
|
|
@@ -134,4 +170,3 @@ var DiscordDriver = class extends Oauth2Driver {
|
|
|
134
170
|
export {
|
|
135
171
|
DiscordDriver
|
|
136
172
|
};
|
|
137
|
-
//# sourceMappingURL=discord.js.map
|
|
@@ -1,9 +1,38 @@
|
|
|
1
1
|
import type { HttpClient } from '@poppinss/oauth-client';
|
|
2
2
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
3
|
-
import type { FacebookToken, FacebookScopes, LiteralStringUnion, ApiRequestContract, FacebookDriverConfig, FacebookProfileFields, RedirectRequestContract } from '../types.
|
|
4
|
-
import { Oauth2Driver } from '../abstract_drivers/oauth2.
|
|
3
|
+
import type { FacebookToken, FacebookScopes, LiteralStringUnion, ApiRequestContract, FacebookDriverConfig, FacebookProfileFields, RedirectRequestContract } from '../types.ts';
|
|
4
|
+
import { Oauth2Driver } from '../abstract_drivers/oauth2.ts';
|
|
5
5
|
/**
|
|
6
|
-
* Facebook driver
|
|
6
|
+
* Facebook OAuth2 driver for authenticating users via Facebook.
|
|
7
|
+
* Supports fetching user profile information including name, email, and profile picture.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* router.get('/facebook/redirect', ({ ally }) => {
|
|
12
|
+
* return ally.use('facebook').redirect((request) => {
|
|
13
|
+
* request.scopes(['email', 'public_profile'])
|
|
14
|
+
* })
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* router.get('/facebook/callback', async ({ ally }) => {
|
|
18
|
+
* const facebook = ally.use('facebook')
|
|
19
|
+
*
|
|
20
|
+
* if (facebook.accessDenied()) {
|
|
21
|
+
* return 'Access was denied'
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* if (facebook.stateMisMatch()) {
|
|
25
|
+
* return 'State mismatch error'
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* if (facebook.hasError()) {
|
|
29
|
+
* return facebook.getError()
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* const user = await facebook.user()
|
|
33
|
+
* return user
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
7
36
|
*/
|
|
8
37
|
export declare class FacebookDriver extends Oauth2Driver<FacebookToken, FacebookScopes> {
|
|
9
38
|
config: FacebookDriverConfig;
|
|
@@ -39,18 +68,33 @@ export declare class FacebookDriver extends Oauth2Driver<FacebookToken, Facebook
|
|
|
39
68
|
* Scopes separator
|
|
40
69
|
*/
|
|
41
70
|
protected scopesSeparator: string;
|
|
71
|
+
/**
|
|
72
|
+
* @param ctx - The HTTP context
|
|
73
|
+
* @param config - Configuration for the Facebook driver
|
|
74
|
+
*/
|
|
42
75
|
constructor(ctx: HttpContext, config: FacebookDriverConfig);
|
|
43
76
|
/**
|
|
44
|
-
*
|
|
77
|
+
* Configures the redirect request with default scopes and Facebook-specific
|
|
78
|
+
* parameters like display and auth_type.
|
|
79
|
+
*
|
|
80
|
+
* @param request - The redirect request to configure
|
|
45
81
|
*/
|
|
46
82
|
protected configureRedirectRequest(request: RedirectRequestContract<FacebookScopes>): void;
|
|
47
83
|
/**
|
|
48
|
-
*
|
|
84
|
+
* Creates an authenticated HTTP request with the proper authorization
|
|
85
|
+
* header for Facebook API calls.
|
|
86
|
+
*
|
|
87
|
+
* @param url - The API endpoint URL
|
|
88
|
+
* @param token - The access token
|
|
49
89
|
*/
|
|
50
90
|
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
|
|
51
91
|
/**
|
|
52
|
-
* Fetches the user
|
|
53
|
-
*
|
|
92
|
+
* Fetches the authenticated user's profile information from the Facebook API.
|
|
93
|
+
*
|
|
94
|
+
* @param token - The access token
|
|
95
|
+
* @param callback - Optional callback to customize the API request
|
|
96
|
+
*
|
|
97
|
+
* @see https://developers.facebook.com/docs/graph-api/reference/user/
|
|
54
98
|
*/
|
|
55
99
|
protected getUserInfo(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
|
|
56
100
|
id: any;
|
|
@@ -62,11 +106,21 @@ export declare class FacebookDriver extends Oauth2Driver<FacebookToken, Facebook
|
|
|
62
106
|
original: any;
|
|
63
107
|
}>;
|
|
64
108
|
/**
|
|
65
|
-
*
|
|
109
|
+
* Check if the error from the callback indicates that the user
|
|
110
|
+
* denied authorization.
|
|
66
111
|
*/
|
|
67
112
|
accessDenied(): boolean;
|
|
68
113
|
/**
|
|
69
|
-
*
|
|
114
|
+
* Get the authenticated user's profile information using
|
|
115
|
+
* the authorization code from the callback request.
|
|
116
|
+
*
|
|
117
|
+
* @param callback - Optional callback to customize the API request
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* const user = await ally.use('facebook').user()
|
|
122
|
+
* console.log(user.name, user.email)
|
|
123
|
+
* ```
|
|
70
124
|
*/
|
|
71
125
|
user(callback?: (request: ApiRequestContract) => void): Promise<{
|
|
72
126
|
token: FacebookToken;
|
|
@@ -79,7 +133,16 @@ export declare class FacebookDriver extends Oauth2Driver<FacebookToken, Facebook
|
|
|
79
133
|
original: any;
|
|
80
134
|
}>;
|
|
81
135
|
/**
|
|
82
|
-
*
|
|
136
|
+
* Get the user's profile information using an existing
|
|
137
|
+
* access token.
|
|
138
|
+
*
|
|
139
|
+
* @param token - The Facebook access token
|
|
140
|
+
* @param callback - Optional callback to customize the API request
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* const user = await ally.use('facebook').userFromToken(accessToken)
|
|
145
|
+
* ```
|
|
83
146
|
*/
|
|
84
147
|
userFromToken(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
|
|
85
148
|
token: {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Oauth2Driver
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
5
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-WM3V3APX.js";
|
|
4
|
+
import "../../chunk-KSJ4CFTC.js";
|
|
5
|
+
import "../../chunk-MLKGABMK.js";
|
|
6
6
|
|
|
7
7
|
// src/drivers/facebook.ts
|
|
8
8
|
var FacebookDriver = class extends Oauth2Driver {
|
|
9
|
+
/**
|
|
10
|
+
* @param ctx - The HTTP context
|
|
11
|
+
* @param config - Configuration for the Facebook driver
|
|
12
|
+
*/
|
|
9
13
|
constructor(ctx, config) {
|
|
10
14
|
super(ctx, config);
|
|
11
15
|
this.config = config;
|
|
@@ -52,7 +56,10 @@ var FacebookDriver = class extends Oauth2Driver {
|
|
|
52
56
|
*/
|
|
53
57
|
scopesSeparator = " ";
|
|
54
58
|
/**
|
|
55
|
-
*
|
|
59
|
+
* Configures the redirect request with default scopes and Facebook-specific
|
|
60
|
+
* parameters like display and auth_type.
|
|
61
|
+
*
|
|
62
|
+
* @param request - The redirect request to configure
|
|
56
63
|
*/
|
|
57
64
|
configureRedirectRequest(request) {
|
|
58
65
|
request.scopes(this.config.scopes || ["email"]);
|
|
@@ -66,7 +73,11 @@ var FacebookDriver = class extends Oauth2Driver {
|
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
/**
|
|
69
|
-
*
|
|
76
|
+
* Creates an authenticated HTTP request with the proper authorization
|
|
77
|
+
* header for Facebook API calls.
|
|
78
|
+
*
|
|
79
|
+
* @param url - The API endpoint URL
|
|
80
|
+
* @param token - The access token
|
|
70
81
|
*/
|
|
71
82
|
getAuthenticatedRequest(url, token) {
|
|
72
83
|
const request = this.httpClient(url);
|
|
@@ -76,8 +87,12 @@ var FacebookDriver = class extends Oauth2Driver {
|
|
|
76
87
|
return request;
|
|
77
88
|
}
|
|
78
89
|
/**
|
|
79
|
-
* Fetches the user
|
|
80
|
-
*
|
|
90
|
+
* Fetches the authenticated user's profile information from the Facebook API.
|
|
91
|
+
*
|
|
92
|
+
* @param token - The access token
|
|
93
|
+
* @param callback - Optional callback to customize the API request
|
|
94
|
+
*
|
|
95
|
+
* @see https://developers.facebook.com/docs/graph-api/reference/user/
|
|
81
96
|
*/
|
|
82
97
|
async getUserInfo(token, callback) {
|
|
83
98
|
const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token);
|
|
@@ -100,7 +115,8 @@ var FacebookDriver = class extends Oauth2Driver {
|
|
|
100
115
|
};
|
|
101
116
|
}
|
|
102
117
|
/**
|
|
103
|
-
*
|
|
118
|
+
* Check if the error from the callback indicates that the user
|
|
119
|
+
* denied authorization.
|
|
104
120
|
*/
|
|
105
121
|
accessDenied() {
|
|
106
122
|
const error = this.getError();
|
|
@@ -110,7 +126,16 @@ var FacebookDriver = class extends Oauth2Driver {
|
|
|
110
126
|
return error === "access_denied";
|
|
111
127
|
}
|
|
112
128
|
/**
|
|
113
|
-
*
|
|
129
|
+
* Get the authenticated user's profile information using
|
|
130
|
+
* the authorization code from the callback request.
|
|
131
|
+
*
|
|
132
|
+
* @param callback - Optional callback to customize the API request
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const user = await ally.use('facebook').user()
|
|
137
|
+
* console.log(user.name, user.email)
|
|
138
|
+
* ```
|
|
114
139
|
*/
|
|
115
140
|
async user(callback) {
|
|
116
141
|
const token = await this.accessToken(callback);
|
|
@@ -121,7 +146,16 @@ var FacebookDriver = class extends Oauth2Driver {
|
|
|
121
146
|
};
|
|
122
147
|
}
|
|
123
148
|
/**
|
|
124
|
-
*
|
|
149
|
+
* Get the user's profile information using an existing
|
|
150
|
+
* access token.
|
|
151
|
+
*
|
|
152
|
+
* @param token - The Facebook access token
|
|
153
|
+
* @param callback - Optional callback to customize the API request
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* const user = await ally.use('facebook').userFromToken(accessToken)
|
|
158
|
+
* ```
|
|
125
159
|
*/
|
|
126
160
|
async userFromToken(token, callback) {
|
|
127
161
|
const user = await this.getUserInfo(token, callback);
|
|
@@ -134,4 +168,3 @@ var FacebookDriver = class extends Oauth2Driver {
|
|
|
134
168
|
export {
|
|
135
169
|
FacebookDriver
|
|
136
170
|
};
|
|
137
|
-
//# sourceMappingURL=facebook.js.map
|
|
@@ -1,9 +1,38 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
2
|
import type { HttpClient } from '@poppinss/oauth-client';
|
|
3
|
-
import type { GithubToken, GithubScopes, AllyUserContract, GithubDriverConfig, ApiRequestContract, RedirectRequestContract } from '../types.
|
|
4
|
-
import { Oauth2Driver } from '../abstract_drivers/oauth2.
|
|
3
|
+
import type { GithubToken, GithubScopes, AllyUserContract, GithubDriverConfig, ApiRequestContract, RedirectRequestContract } from '../types.ts';
|
|
4
|
+
import { Oauth2Driver } from '../abstract_drivers/oauth2.ts';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* GitHub OAuth2 driver for authenticating users via GitHub.
|
|
7
|
+
* Supports fetching user profile information and email addresses.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* router.get('/github/redirect', ({ ally }) => {
|
|
12
|
+
* return ally.use('github').redirect((request) => {
|
|
13
|
+
* request.scopes(['user:email', 'read:org'])
|
|
14
|
+
* })
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* router.get('/github/callback', async ({ ally }) => {
|
|
18
|
+
* const github = ally.use('github')
|
|
19
|
+
*
|
|
20
|
+
* if (github.accessDenied()) {
|
|
21
|
+
* return 'Access was denied'
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* if (github.stateMisMatch()) {
|
|
25
|
+
* return 'State mismatch error'
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* if (github.hasError()) {
|
|
29
|
+
* return github.getError()
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* const user = await github.user()
|
|
33
|
+
* return user
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
7
36
|
*/
|
|
8
37
|
export declare class GithubDriver extends Oauth2Driver<GithubToken, GithubScopes> {
|
|
9
38
|
config: GithubDriverConfig;
|
|
@@ -36,22 +65,40 @@ export declare class GithubDriver extends Oauth2Driver<GithubToken, GithubScopes
|
|
|
36
65
|
* Scopes separator
|
|
37
66
|
*/
|
|
38
67
|
protected scopesSeparator: string;
|
|
68
|
+
/**
|
|
69
|
+
* @param ctx - The HTTP context
|
|
70
|
+
* @param config - Configuration for the GitHub driver
|
|
71
|
+
*/
|
|
39
72
|
constructor(ctx: HttpContext, config: GithubDriverConfig);
|
|
40
73
|
/**
|
|
41
|
-
*
|
|
74
|
+
* Configures the redirect request with default scopes and GitHub-specific
|
|
75
|
+
* parameters like allow_signup and login.
|
|
76
|
+
*
|
|
77
|
+
* @param request - The redirect request to configure
|
|
42
78
|
*/
|
|
43
79
|
protected configureRedirectRequest(request: RedirectRequestContract<GithubScopes>): void;
|
|
44
80
|
/**
|
|
45
|
-
*
|
|
81
|
+
* Configures the access token request with GitHub-specific requirements.
|
|
82
|
+
* GitHub doesn't accept the grant_type field that is set by default.
|
|
83
|
+
*
|
|
84
|
+
* @param request - The API request to configure
|
|
46
85
|
*/
|
|
47
86
|
protected configureAccessTokenRequest(request: ApiRequestContract): void;
|
|
48
87
|
/**
|
|
49
|
-
*
|
|
88
|
+
* Creates an authenticated HTTP request with the proper authorization
|
|
89
|
+
* header for GitHub API calls.
|
|
90
|
+
*
|
|
91
|
+
* @param url - The API endpoint URL
|
|
92
|
+
* @param token - The access token
|
|
50
93
|
*/
|
|
51
94
|
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
|
|
52
95
|
/**
|
|
53
|
-
* Fetches the user
|
|
54
|
-
*
|
|
96
|
+
* Fetches the authenticated user's profile information from the GitHub API.
|
|
97
|
+
*
|
|
98
|
+
* @param token - The access token
|
|
99
|
+
* @param callback - Optional callback to customize the API request
|
|
100
|
+
*
|
|
101
|
+
* @see https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
|
|
55
102
|
*/
|
|
56
103
|
protected getUserInfo(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
|
|
57
104
|
id: any;
|
|
@@ -63,16 +110,32 @@ export declare class GithubDriver extends Oauth2Driver<GithubToken, GithubScopes
|
|
|
63
110
|
original: any;
|
|
64
111
|
}>;
|
|
65
112
|
/**
|
|
66
|
-
* Fetches the user email from the
|
|
67
|
-
*
|
|
113
|
+
* Fetches the user's email addresses from the GitHub API. This is needed
|
|
114
|
+
* when the user's email is not included in the basic profile response.
|
|
115
|
+
* Returns the primary verified email, or the first available email.
|
|
116
|
+
*
|
|
117
|
+
* @param token - The access token
|
|
118
|
+
* @param callback - Optional callback to customize the API request
|
|
119
|
+
*
|
|
120
|
+
* @see https://docs.github.com/en/rest/reference/users#list-email-addresses-for-the-authenticated-user
|
|
68
121
|
*/
|
|
69
122
|
protected getUserEmail(token: string, callback?: (request: ApiRequestContract) => void): Promise<any>;
|
|
70
123
|
/**
|
|
71
|
-
*
|
|
124
|
+
* Check if the error from the callback indicates that the user
|
|
125
|
+
* denied authorization.
|
|
72
126
|
*/
|
|
73
127
|
accessDenied(): boolean;
|
|
74
128
|
/**
|
|
75
|
-
*
|
|
129
|
+
* Get the authenticated user's profile and email information using
|
|
130
|
+
* the authorization code from the callback request.
|
|
131
|
+
*
|
|
132
|
+
* @param callback - Optional callback to customize the API request
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const user = await ally.use('github').user()
|
|
137
|
+
* console.log(user.name, user.email)
|
|
138
|
+
* ```
|
|
76
139
|
*/
|
|
77
140
|
user(callback?: (request: ApiRequestContract) => void): Promise<{
|
|
78
141
|
token: GithubToken;
|
|
@@ -85,7 +148,16 @@ export declare class GithubDriver extends Oauth2Driver<GithubToken, GithubScopes
|
|
|
85
148
|
original: any;
|
|
86
149
|
}>;
|
|
87
150
|
/**
|
|
88
|
-
*
|
|
151
|
+
* Get the user's profile and email information using an existing
|
|
152
|
+
* access token.
|
|
153
|
+
*
|
|
154
|
+
* @param token - The GitHub access token
|
|
155
|
+
* @param callback - Optional callback to customize the API request
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* const user = await ally.use('github').userFromToken(accessToken)
|
|
160
|
+
* ```
|
|
89
161
|
*/
|
|
90
162
|
userFromToken(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
|
|
91
163
|
token: {
|