@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,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/github.ts
|
|
8
8
|
var GithubDriver = class extends Oauth2Driver {
|
|
9
|
+
/**
|
|
10
|
+
* @param ctx - The HTTP context
|
|
11
|
+
* @param config - Configuration for the GitHub driver
|
|
12
|
+
*/
|
|
9
13
|
constructor(ctx, config) {
|
|
10
14
|
super(ctx, config);
|
|
11
15
|
this.config = config;
|
|
@@ -41,7 +45,10 @@ var GithubDriver = class extends Oauth2Driver {
|
|
|
41
45
|
*/
|
|
42
46
|
scopesSeparator = " ";
|
|
43
47
|
/**
|
|
44
|
-
*
|
|
48
|
+
* Configures the redirect request with default scopes and GitHub-specific
|
|
49
|
+
* parameters like allow_signup and login.
|
|
50
|
+
*
|
|
51
|
+
* @param request - The redirect request to configure
|
|
45
52
|
*/
|
|
46
53
|
configureRedirectRequest(request) {
|
|
47
54
|
request.scopes(this.config.scopes || ["user"]);
|
|
@@ -53,7 +60,10 @@ var GithubDriver = class extends Oauth2Driver {
|
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
62
|
/**
|
|
56
|
-
*
|
|
63
|
+
* Configures the access token request with GitHub-specific requirements.
|
|
64
|
+
* GitHub doesn't accept the grant_type field that is set by default.
|
|
65
|
+
*
|
|
66
|
+
* @param request - The API request to configure
|
|
57
67
|
*/
|
|
58
68
|
configureAccessTokenRequest(request) {
|
|
59
69
|
if (!this.isStateless) {
|
|
@@ -62,7 +72,11 @@ var GithubDriver = class extends Oauth2Driver {
|
|
|
62
72
|
request.clearField("grant_type");
|
|
63
73
|
}
|
|
64
74
|
/**
|
|
65
|
-
*
|
|
75
|
+
* Creates an authenticated HTTP request with the proper authorization
|
|
76
|
+
* header for GitHub API calls.
|
|
77
|
+
*
|
|
78
|
+
* @param url - The API endpoint URL
|
|
79
|
+
* @param token - The access token
|
|
66
80
|
*/
|
|
67
81
|
getAuthenticatedRequest(url, token) {
|
|
68
82
|
const request = this.httpClient(url);
|
|
@@ -72,8 +86,12 @@ var GithubDriver = class extends Oauth2Driver {
|
|
|
72
86
|
return request;
|
|
73
87
|
}
|
|
74
88
|
/**
|
|
75
|
-
* Fetches the user
|
|
76
|
-
*
|
|
89
|
+
* Fetches the authenticated user's profile information from the GitHub API.
|
|
90
|
+
*
|
|
91
|
+
* @param token - The access token
|
|
92
|
+
* @param callback - Optional callback to customize the API request
|
|
93
|
+
*
|
|
94
|
+
* @see https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
|
|
77
95
|
*/
|
|
78
96
|
async getUserInfo(token, callback) {
|
|
79
97
|
const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token);
|
|
@@ -93,8 +111,14 @@ var GithubDriver = class extends Oauth2Driver {
|
|
|
93
111
|
};
|
|
94
112
|
}
|
|
95
113
|
/**
|
|
96
|
-
* Fetches the user email from the
|
|
97
|
-
*
|
|
114
|
+
* Fetches the user's email addresses from the GitHub API. This is needed
|
|
115
|
+
* when the user's email is not included in the basic profile response.
|
|
116
|
+
* Returns the primary verified email, or the first available email.
|
|
117
|
+
*
|
|
118
|
+
* @param token - The access token
|
|
119
|
+
* @param callback - Optional callback to customize the API request
|
|
120
|
+
*
|
|
121
|
+
* @see https://docs.github.com/en/rest/reference/users#list-email-addresses-for-the-authenticated-user
|
|
98
122
|
*/
|
|
99
123
|
async getUserEmail(token, callback) {
|
|
100
124
|
const request = this.getAuthenticatedRequest(
|
|
@@ -120,7 +144,8 @@ var GithubDriver = class extends Oauth2Driver {
|
|
|
120
144
|
}
|
|
121
145
|
}
|
|
122
146
|
/**
|
|
123
|
-
*
|
|
147
|
+
* Check if the error from the callback indicates that the user
|
|
148
|
+
* denied authorization.
|
|
124
149
|
*/
|
|
125
150
|
accessDenied() {
|
|
126
151
|
const error = this.getError();
|
|
@@ -130,7 +155,16 @@ var GithubDriver = class extends Oauth2Driver {
|
|
|
130
155
|
return error === "access_denied";
|
|
131
156
|
}
|
|
132
157
|
/**
|
|
133
|
-
*
|
|
158
|
+
* Get the authenticated user's profile and email information using
|
|
159
|
+
* the authorization code from the callback request.
|
|
160
|
+
*
|
|
161
|
+
* @param callback - Optional callback to customize the API request
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const user = await ally.use('github').user()
|
|
166
|
+
* console.log(user.name, user.email)
|
|
167
|
+
* ```
|
|
134
168
|
*/
|
|
135
169
|
async user(callback) {
|
|
136
170
|
const token = await this.accessToken(callback);
|
|
@@ -149,7 +183,16 @@ var GithubDriver = class extends Oauth2Driver {
|
|
|
149
183
|
};
|
|
150
184
|
}
|
|
151
185
|
/**
|
|
152
|
-
*
|
|
186
|
+
* Get the user's profile and email information using an existing
|
|
187
|
+
* access token.
|
|
188
|
+
*
|
|
189
|
+
* @param token - The GitHub access token
|
|
190
|
+
* @param callback - Optional callback to customize the API request
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* const user = await ally.use('github').userFromToken(accessToken)
|
|
195
|
+
* ```
|
|
153
196
|
*/
|
|
154
197
|
async userFromToken(token, callback) {
|
|
155
198
|
const user = await this.getUserInfo(token, callback);
|
|
@@ -170,4 +213,3 @@ var GithubDriver = class extends Oauth2Driver {
|
|
|
170
213
|
export {
|
|
171
214
|
GithubDriver
|
|
172
215
|
};
|
|
173
|
-
//# sourceMappingURL=github.js.map
|
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
2
|
import type { HttpClient } from '@poppinss/oauth-client';
|
|
3
|
-
import type { GoogleToken, GoogleScopes, GoogleDriverConfig, ApiRequestContract, RedirectRequestContract } from '../types.
|
|
4
|
-
import { Oauth2Driver } from '../abstract_drivers/oauth2.
|
|
3
|
+
import type { GoogleToken, GoogleScopes, GoogleDriverConfig, ApiRequestContract, RedirectRequestContract } from '../types.ts';
|
|
4
|
+
import { Oauth2Driver } from '../abstract_drivers/oauth2.ts';
|
|
5
5
|
/**
|
|
6
|
-
* Google driver
|
|
6
|
+
* Google OAuth2 driver for authenticating users via Google.
|
|
7
|
+
* Supports fetching user profile information including name, email, and profile picture.
|
|
8
|
+
* Automatically prefixes scopes with the appropriate Google API URL.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* router.get('/google/redirect', ({ ally }) => {
|
|
13
|
+
* return ally.use('google').redirect((request) => {
|
|
14
|
+
* request.scopes(['userinfo.email', 'userinfo.profile', 'calendar.readonly'])
|
|
15
|
+
* })
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* router.get('/google/callback', async ({ ally }) => {
|
|
19
|
+
* const google = ally.use('google')
|
|
20
|
+
*
|
|
21
|
+
* if (google.accessDenied()) {
|
|
22
|
+
* return 'Access was denied'
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* if (google.stateMisMatch()) {
|
|
26
|
+
* return 'State mismatch error'
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* if (google.hasError()) {
|
|
30
|
+
* return google.getError()
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* const user = await google.user()
|
|
34
|
+
* return user
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
7
37
|
*/
|
|
8
38
|
export declare class GoogleDriver extends Oauth2Driver<GoogleToken, GoogleScopes> {
|
|
9
39
|
config: GoogleDriverConfig;
|
|
@@ -35,17 +65,31 @@ export declare class GoogleDriver extends Oauth2Driver<GoogleToken, GoogleScopes
|
|
|
35
65
|
* Scopes separator
|
|
36
66
|
*/
|
|
37
67
|
protected scopesSeparator: string;
|
|
68
|
+
/**
|
|
69
|
+
* @param ctx - The HTTP context
|
|
70
|
+
* @param config - Configuration for the Google driver
|
|
71
|
+
*/
|
|
38
72
|
constructor(ctx: HttpContext, config: GoogleDriverConfig);
|
|
39
73
|
/**
|
|
40
|
-
*
|
|
74
|
+
* Configures the redirect request with default scopes and Google-specific
|
|
75
|
+
* parameters like access_type, prompt, display, and hosted domain.
|
|
76
|
+
*
|
|
77
|
+
* @param request - The redirect request to configure
|
|
41
78
|
*/
|
|
42
79
|
protected configureRedirectRequest(request: RedirectRequestContract<GoogleScopes>): void;
|
|
43
80
|
/**
|
|
44
|
-
*
|
|
81
|
+
* Creates an authenticated HTTP request with the proper authorization
|
|
82
|
+
* header for Google API calls.
|
|
83
|
+
*
|
|
84
|
+
* @param url - The API endpoint URL
|
|
85
|
+
* @param token - The access token
|
|
45
86
|
*/
|
|
46
87
|
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
|
|
47
88
|
/**
|
|
48
|
-
* Fetches the user
|
|
89
|
+
* Fetches the authenticated user's profile information from the Google API.
|
|
90
|
+
*
|
|
91
|
+
* @param token - The access token
|
|
92
|
+
* @param callback - Optional callback to customize the API request
|
|
49
93
|
*/
|
|
50
94
|
protected getUserInfo(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
|
|
51
95
|
id: any;
|
|
@@ -57,15 +101,28 @@ export declare class GoogleDriver extends Oauth2Driver<GoogleToken, GoogleScopes
|
|
|
57
101
|
original: any;
|
|
58
102
|
}>;
|
|
59
103
|
/**
|
|
60
|
-
*
|
|
104
|
+
* Check if the error from the callback indicates that the user
|
|
105
|
+
* denied authorization.
|
|
61
106
|
*/
|
|
62
107
|
accessDenied(): boolean;
|
|
63
108
|
/**
|
|
64
|
-
* Get access token
|
|
109
|
+
* Get the access token using the authorization code from the callback request.
|
|
110
|
+
* Returns a GoogleToken that includes the ID token.
|
|
111
|
+
*
|
|
112
|
+
* @param callback - Optional callback to customize the API request
|
|
65
113
|
*/
|
|
66
114
|
accessToken(callback?: (request: ApiRequestContract) => void): Promise<GoogleToken>;
|
|
67
115
|
/**
|
|
68
|
-
*
|
|
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('google').user()
|
|
124
|
+
* console.log(user.name, user.email)
|
|
125
|
+
* ```
|
|
69
126
|
*/
|
|
70
127
|
user(callback?: (request: ApiRequestContract) => void): Promise<{
|
|
71
128
|
token: GoogleToken;
|
|
@@ -78,7 +135,16 @@ export declare class GoogleDriver extends Oauth2Driver<GoogleToken, GoogleScopes
|
|
|
78
135
|
original: any;
|
|
79
136
|
}>;
|
|
80
137
|
/**
|
|
81
|
-
*
|
|
138
|
+
* Get the user's profile information using an existing
|
|
139
|
+
* access token.
|
|
140
|
+
*
|
|
141
|
+
* @param token - The Google access token
|
|
142
|
+
* @param callback - Optional callback to customize the API request
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const user = await ally.use('google').userFromToken(accessToken)
|
|
147
|
+
* ```
|
|
82
148
|
*/
|
|
83
149
|
userFromToken(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
|
|
84
150
|
token: {
|
|
@@ -94,7 +160,10 @@ export declare class GoogleDriver extends Oauth2Driver<GoogleToken, GoogleScopes
|
|
|
94
160
|
original: any;
|
|
95
161
|
}>;
|
|
96
162
|
/**
|
|
97
|
-
* Prefixes
|
|
163
|
+
* Prefixes Google scopes with the appropriate API URL.
|
|
164
|
+
* Converts short scope names like 'userinfo.email' to full URLs.
|
|
165
|
+
*
|
|
166
|
+
* @param scopes - Array of scope names to prefix
|
|
98
167
|
*/
|
|
99
168
|
buildScopes(scopes: string[]): string[];
|
|
100
169
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
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/google.ts
|
|
8
8
|
var SCOPE_PREFIXES = {
|
|
@@ -43,6 +43,10 @@ var SCOPE_PREFIXES = {
|
|
|
43
43
|
]
|
|
44
44
|
};
|
|
45
45
|
var GoogleDriver = class extends Oauth2Driver {
|
|
46
|
+
/**
|
|
47
|
+
* @param ctx - The HTTP context
|
|
48
|
+
* @param config - Configuration for the Google driver
|
|
49
|
+
*/
|
|
46
50
|
constructor(ctx, config) {
|
|
47
51
|
super(ctx, config);
|
|
48
52
|
this.config = config;
|
|
@@ -77,7 +81,10 @@ var GoogleDriver = class extends Oauth2Driver {
|
|
|
77
81
|
*/
|
|
78
82
|
scopesSeparator = " ";
|
|
79
83
|
/**
|
|
80
|
-
*
|
|
84
|
+
* Configures the redirect request with default scopes and Google-specific
|
|
85
|
+
* parameters like access_type, prompt, display, and hosted domain.
|
|
86
|
+
*
|
|
87
|
+
* @param request - The redirect request to configure
|
|
81
88
|
*/
|
|
82
89
|
configureRedirectRequest(request) {
|
|
83
90
|
request.transformScopes((scopes) => this.buildScopes(scopes));
|
|
@@ -97,7 +104,11 @@ var GoogleDriver = class extends Oauth2Driver {
|
|
|
97
104
|
}
|
|
98
105
|
}
|
|
99
106
|
/**
|
|
100
|
-
*
|
|
107
|
+
* Creates an authenticated HTTP request with the proper authorization
|
|
108
|
+
* header for Google API calls.
|
|
109
|
+
*
|
|
110
|
+
* @param url - The API endpoint URL
|
|
111
|
+
* @param token - The access token
|
|
101
112
|
*/
|
|
102
113
|
getAuthenticatedRequest(url, token) {
|
|
103
114
|
const request = this.httpClient(url);
|
|
@@ -107,7 +118,10 @@ var GoogleDriver = class extends Oauth2Driver {
|
|
|
107
118
|
return request;
|
|
108
119
|
}
|
|
109
120
|
/**
|
|
110
|
-
* Fetches the user
|
|
121
|
+
* Fetches the authenticated user's profile information from the Google API.
|
|
122
|
+
*
|
|
123
|
+
* @param token - The access token
|
|
124
|
+
* @param callback - Optional callback to customize the API request
|
|
111
125
|
*/
|
|
112
126
|
async getUserInfo(token, callback) {
|
|
113
127
|
const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token);
|
|
@@ -126,7 +140,8 @@ var GoogleDriver = class extends Oauth2Driver {
|
|
|
126
140
|
};
|
|
127
141
|
}
|
|
128
142
|
/**
|
|
129
|
-
*
|
|
143
|
+
* Check if the error from the callback indicates that the user
|
|
144
|
+
* denied authorization.
|
|
130
145
|
*/
|
|
131
146
|
accessDenied() {
|
|
132
147
|
const error = this.getError();
|
|
@@ -136,7 +151,10 @@ var GoogleDriver = class extends Oauth2Driver {
|
|
|
136
151
|
return error === "access_denied";
|
|
137
152
|
}
|
|
138
153
|
/**
|
|
139
|
-
* Get access token
|
|
154
|
+
* Get the access token using the authorization code from the callback request.
|
|
155
|
+
* Returns a GoogleToken that includes the ID token.
|
|
156
|
+
*
|
|
157
|
+
* @param callback - Optional callback to customize the API request
|
|
140
158
|
*/
|
|
141
159
|
async accessToken(callback) {
|
|
142
160
|
const token = await super.accessToken(callback);
|
|
@@ -146,7 +164,16 @@ var GoogleDriver = class extends Oauth2Driver {
|
|
|
146
164
|
};
|
|
147
165
|
}
|
|
148
166
|
/**
|
|
149
|
-
*
|
|
167
|
+
* Get the authenticated user's profile information using
|
|
168
|
+
* the authorization code from the callback request.
|
|
169
|
+
*
|
|
170
|
+
* @param callback - Optional callback to customize the API request
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const user = await ally.use('google').user()
|
|
175
|
+
* console.log(user.name, user.email)
|
|
176
|
+
* ```
|
|
150
177
|
*/
|
|
151
178
|
async user(callback) {
|
|
152
179
|
const token = await this.accessToken(callback);
|
|
@@ -157,7 +184,16 @@ var GoogleDriver = class extends Oauth2Driver {
|
|
|
157
184
|
};
|
|
158
185
|
}
|
|
159
186
|
/**
|
|
160
|
-
*
|
|
187
|
+
* Get the user's profile information using an existing
|
|
188
|
+
* access token.
|
|
189
|
+
*
|
|
190
|
+
* @param token - The Google access token
|
|
191
|
+
* @param callback - Optional callback to customize the API request
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* const user = await ally.use('google').userFromToken(accessToken)
|
|
196
|
+
* ```
|
|
161
197
|
*/
|
|
162
198
|
async userFromToken(token, callback) {
|
|
163
199
|
const user = await this.getUserInfo(token, callback);
|
|
@@ -167,7 +203,10 @@ var GoogleDriver = class extends Oauth2Driver {
|
|
|
167
203
|
};
|
|
168
204
|
}
|
|
169
205
|
/**
|
|
170
|
-
* Prefixes
|
|
206
|
+
* Prefixes Google scopes with the appropriate API URL.
|
|
207
|
+
* Converts short scope names like 'userinfo.email' to full URLs.
|
|
208
|
+
*
|
|
209
|
+
* @param scopes - Array of scope names to prefix
|
|
171
210
|
*/
|
|
172
211
|
buildScopes(scopes) {
|
|
173
212
|
return scopes.map((name) => {
|
|
@@ -181,4 +220,3 @@ var GoogleDriver = class extends Oauth2Driver {
|
|
|
181
220
|
export {
|
|
182
221
|
GoogleDriver
|
|
183
222
|
};
|
|
184
|
-
//# sourceMappingURL=google.js.map
|
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
2
|
import type { HttpClient } from '@poppinss/oauth-client';
|
|
3
|
-
import type { LinkedInToken, LinkedInScopes, ApiRequestContract, LinkedInDriverConfig, RedirectRequestContract } from '../types.
|
|
4
|
-
import { Oauth2Driver } from '../abstract_drivers/oauth2.
|
|
3
|
+
import type { LinkedInToken, LinkedInScopes, ApiRequestContract, LinkedInDriverConfig, RedirectRequestContract } from '../types.ts';
|
|
4
|
+
import { Oauth2Driver } from '../abstract_drivers/oauth2.ts';
|
|
5
5
|
/**
|
|
6
|
-
* LinkedIn driver
|
|
6
|
+
* LinkedIn OAuth2 driver for authenticating users via LinkedIn.
|
|
7
|
+
* Supports fetching user profile information including name, email, and profile picture.
|
|
8
|
+
* Note: This driver fetches email separately as it's not included in the basic profile.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* router.get('/linkedin/redirect', ({ ally }) => {
|
|
13
|
+
* return ally.use('linkedin').redirect((request) => {
|
|
14
|
+
* request.scopes(['r_emailaddress', 'r_liteprofile'])
|
|
15
|
+
* })
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* router.get('/linkedin/callback', async ({ ally }) => {
|
|
19
|
+
* const linkedin = ally.use('linkedin')
|
|
20
|
+
*
|
|
21
|
+
* if (linkedin.accessDenied()) {
|
|
22
|
+
* return 'Access was denied'
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* if (linkedin.stateMisMatch()) {
|
|
26
|
+
* return 'State mismatch error'
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* if (linkedin.hasError()) {
|
|
30
|
+
* return linkedin.getError()
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* const user = await linkedin.user()
|
|
34
|
+
* return user
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
7
37
|
*/
|
|
8
38
|
export declare class LinkedInDriver extends Oauth2Driver<LinkedInToken, LinkedInScopes> {
|
|
9
39
|
config: LinkedInDriverConfig;
|
|
@@ -36,17 +66,30 @@ export declare class LinkedInDriver extends Oauth2Driver<LinkedInToken, LinkedIn
|
|
|
36
66
|
* Scopes separator
|
|
37
67
|
*/
|
|
38
68
|
protected scopesSeparator: string;
|
|
69
|
+
/**
|
|
70
|
+
* @param ctx - The HTTP context
|
|
71
|
+
* @param config - Configuration for the LinkedIn driver
|
|
72
|
+
*/
|
|
39
73
|
constructor(ctx: HttpContext, config: LinkedInDriverConfig);
|
|
40
74
|
/**
|
|
41
|
-
*
|
|
75
|
+
* Configures the redirect request with default scopes.
|
|
76
|
+
*
|
|
77
|
+
* @param request - The redirect request to configure
|
|
42
78
|
*/
|
|
43
79
|
protected configureRedirectRequest(request: RedirectRequestContract<LinkedInScopes>): void;
|
|
44
80
|
/**
|
|
45
|
-
*
|
|
81
|
+
* Creates an authenticated HTTP request with the proper authorization
|
|
82
|
+
* header for LinkedIn API calls.
|
|
83
|
+
*
|
|
84
|
+
* @param url - The API endpoint URL
|
|
85
|
+
* @param token - The access token
|
|
46
86
|
*/
|
|
47
87
|
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
|
|
48
88
|
/**
|
|
49
|
-
* Fetches the user
|
|
89
|
+
* Fetches the authenticated user's profile information from the LinkedIn API.
|
|
90
|
+
*
|
|
91
|
+
* @param token - The access token
|
|
92
|
+
* @param callback - Optional callback to customize the API request
|
|
50
93
|
*/
|
|
51
94
|
protected getUserInfo(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
|
|
52
95
|
id: any;
|
|
@@ -56,15 +99,29 @@ export declare class LinkedInDriver extends Oauth2Driver<LinkedInToken, LinkedIn
|
|
|
56
99
|
original: any;
|
|
57
100
|
}>;
|
|
58
101
|
/**
|
|
59
|
-
* Fetches the user email from the LinkedIn API
|
|
102
|
+
* Fetches the user's email address from the LinkedIn API.
|
|
103
|
+
* Requires the 'r_emailaddress' scope.
|
|
104
|
+
*
|
|
105
|
+
* @param token - The access token
|
|
106
|
+
* @param callback - Optional callback to customize the API request
|
|
60
107
|
*/
|
|
61
108
|
protected getUserEmail(token: string, callback?: (request: ApiRequestContract) => void): Promise<any>;
|
|
62
109
|
/**
|
|
63
|
-
*
|
|
110
|
+
* Check if the error from the callback indicates that the user
|
|
111
|
+
* denied authorization or cancelled the login.
|
|
64
112
|
*/
|
|
65
113
|
accessDenied(): boolean;
|
|
66
114
|
/**
|
|
67
|
-
*
|
|
115
|
+
* Get the authenticated user's profile and email information using
|
|
116
|
+
* the authorization code from the callback request.
|
|
117
|
+
*
|
|
118
|
+
* @param callback - Optional callback to customize the API request
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const user = await ally.use('linkedin').user()
|
|
123
|
+
* console.log(user.name, user.email)
|
|
124
|
+
* ```
|
|
68
125
|
*/
|
|
69
126
|
user(callback?: (request: ApiRequestContract) => void): Promise<{
|
|
70
127
|
email: any;
|
|
@@ -77,7 +134,16 @@ export declare class LinkedInDriver extends Oauth2Driver<LinkedInToken, LinkedIn
|
|
|
77
134
|
original: any;
|
|
78
135
|
}>;
|
|
79
136
|
/**
|
|
80
|
-
*
|
|
137
|
+
* Get the user's profile and email information using an existing
|
|
138
|
+
* access token.
|
|
139
|
+
*
|
|
140
|
+
* @param token - The LinkedIn access token
|
|
141
|
+
* @param callback - Optional callback to customize the API request
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const user = await ally.use('linkedin').userFromToken(accessToken)
|
|
146
|
+
* ```
|
|
81
147
|
*/
|
|
82
148
|
userFromToken(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
|
|
83
149
|
email: any;
|
|
@@ -1,12 +1,16 @@
|
|
|
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/linked_in.ts
|
|
8
|
-
import { Exception } from "@
|
|
8
|
+
import { Exception } from "@adonisjs/core/exceptions";
|
|
9
9
|
var LinkedInDriver = class extends Oauth2Driver {
|
|
10
|
+
/**
|
|
11
|
+
* @param ctx - The HTTP context
|
|
12
|
+
* @param config - Configuration for the LinkedIn driver
|
|
13
|
+
*/
|
|
10
14
|
constructor(ctx, config) {
|
|
11
15
|
super(ctx, config);
|
|
12
16
|
this.config = config;
|
|
@@ -42,14 +46,20 @@ var LinkedInDriver = class extends Oauth2Driver {
|
|
|
42
46
|
*/
|
|
43
47
|
scopesSeparator = " ";
|
|
44
48
|
/**
|
|
45
|
-
*
|
|
49
|
+
* Configures the redirect request with default scopes.
|
|
50
|
+
*
|
|
51
|
+
* @param request - The redirect request to configure
|
|
46
52
|
*/
|
|
47
53
|
configureRedirectRequest(request) {
|
|
48
54
|
request.scopes(this.config.scopes || ["r_emailaddress", "r_liteprofile"]);
|
|
49
55
|
request.param("response_type", "code");
|
|
50
56
|
}
|
|
51
57
|
/**
|
|
52
|
-
*
|
|
58
|
+
* Creates an authenticated HTTP request with the proper authorization
|
|
59
|
+
* header for LinkedIn API calls.
|
|
60
|
+
*
|
|
61
|
+
* @param url - The API endpoint URL
|
|
62
|
+
* @param token - The access token
|
|
53
63
|
*/
|
|
54
64
|
getAuthenticatedRequest(url, token) {
|
|
55
65
|
const request = this.httpClient(url);
|
|
@@ -59,7 +69,10 @@ var LinkedInDriver = class extends Oauth2Driver {
|
|
|
59
69
|
return request;
|
|
60
70
|
}
|
|
61
71
|
/**
|
|
62
|
-
* Fetches the user
|
|
72
|
+
* Fetches the authenticated user's profile information from the LinkedIn API.
|
|
73
|
+
*
|
|
74
|
+
* @param token - The access token
|
|
75
|
+
* @param callback - Optional callback to customize the API request
|
|
63
76
|
*/
|
|
64
77
|
async getUserInfo(token, callback) {
|
|
65
78
|
let url = this.config.userInfoUrl || this.userInfoUrl;
|
|
@@ -88,7 +101,11 @@ var LinkedInDriver = class extends Oauth2Driver {
|
|
|
88
101
|
};
|
|
89
102
|
}
|
|
90
103
|
/**
|
|
91
|
-
* Fetches the user email from the LinkedIn API
|
|
104
|
+
* Fetches the user's email address from the LinkedIn API.
|
|
105
|
+
* Requires the 'r_emailaddress' scope.
|
|
106
|
+
*
|
|
107
|
+
* @param token - The access token
|
|
108
|
+
* @param callback - Optional callback to customize the API request
|
|
92
109
|
*/
|
|
93
110
|
async getUserEmail(token, callback) {
|
|
94
111
|
let url = this.config.userEmailUrl || this.userEmailUrl;
|
|
@@ -110,7 +127,8 @@ var LinkedInDriver = class extends Oauth2Driver {
|
|
|
110
127
|
return mainEmail["handle~"]["emailAddress"];
|
|
111
128
|
}
|
|
112
129
|
/**
|
|
113
|
-
*
|
|
130
|
+
* Check if the error from the callback indicates that the user
|
|
131
|
+
* denied authorization or cancelled the login.
|
|
114
132
|
*/
|
|
115
133
|
accessDenied() {
|
|
116
134
|
const error = this.getError();
|
|
@@ -120,7 +138,16 @@ var LinkedInDriver = class extends Oauth2Driver {
|
|
|
120
138
|
return error === "user_cancelled_login" || error === "user_cancelled_authorize";
|
|
121
139
|
}
|
|
122
140
|
/**
|
|
123
|
-
*
|
|
141
|
+
* Get the authenticated user's profile and email information using
|
|
142
|
+
* the authorization code from the callback request.
|
|
143
|
+
*
|
|
144
|
+
* @param callback - Optional callback to customize the API request
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* const user = await ally.use('linkedin').user()
|
|
149
|
+
* console.log(user.name, user.email)
|
|
150
|
+
* ```
|
|
124
151
|
*/
|
|
125
152
|
async user(callback) {
|
|
126
153
|
const token = await this.accessToken(callback);
|
|
@@ -134,7 +161,16 @@ var LinkedInDriver = class extends Oauth2Driver {
|
|
|
134
161
|
};
|
|
135
162
|
}
|
|
136
163
|
/**
|
|
137
|
-
*
|
|
164
|
+
* Get the user's profile and email information using an existing
|
|
165
|
+
* access token.
|
|
166
|
+
*
|
|
167
|
+
* @param token - The LinkedIn access token
|
|
168
|
+
* @param callback - Optional callback to customize the API request
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const user = await ally.use('linkedin').userFromToken(accessToken)
|
|
173
|
+
* ```
|
|
138
174
|
*/
|
|
139
175
|
async userFromToken(token, callback) {
|
|
140
176
|
const user = await this.getUserInfo(token, callback);
|
|
@@ -150,4 +186,3 @@ var LinkedInDriver = class extends Oauth2Driver {
|
|
|
150
186
|
export {
|
|
151
187
|
LinkedInDriver
|
|
152
188
|
};
|
|
153
|
-
//# sourceMappingURL=linked_in.js.map
|