@adonisjs/ally 5.0.0-4 → 5.0.0-6
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/index.d.ts +3 -5
- package/build/index.js +3 -5
- package/build/providers/ally_provider.d.ts +6 -0
- package/build/providers/ally_provider.js +18 -5
- package/build/src/abstract_drivers/oauth1.d.ts +1 -1
- package/build/src/abstract_drivers/oauth1.js +1 -1
- package/build/src/abstract_drivers/oauth2.d.ts +1 -1
- package/build/src/abstract_drivers/oauth2.js +1 -1
- package/build/src/debug.d.ts +1 -1
- package/build/src/define_config.d.ts +29 -10
- package/build/src/define_config.js +62 -18
- package/build/src/drivers/discord.d.ts +4 -3
- package/build/src/drivers/facebook.d.ts +4 -3
- package/build/src/drivers/github.d.ts +4 -3
- package/build/src/drivers/google.d.ts +4 -3
- package/build/src/drivers/linked_in.d.ts +4 -3
- package/build/src/drivers/spotify.d.ts +4 -3
- package/build/src/drivers/twitter.d.ts +2 -2
- package/build/src/types.d.ts +15 -44
- package/build/stubs/config.stub +6 -7
- package/package.json +19 -19
- package/build/src/bindings/http_context.d.ts +0 -6
- package/build/src/bindings/http_context.js +0 -19
- package/build/src/bindings/types.d.ts +0 -12
- package/build/src/bindings/types.js +0 -9
- package/build/src/defaults/config.d.ts +0 -50
- package/build/src/defaults/config.js +0 -58
- package/build/src/drivers_collection.d.ts +0 -23
- package/build/src/drivers_collection.js +0 -72
package/build/index.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import './src/bindings/types.js';
|
|
2
1
|
export { HttpClient as ApiRequest } from '@poppinss/oauth-client';
|
|
3
2
|
export * as errors from './src/errors.js';
|
|
3
|
+
export { configure } from './configure.js';
|
|
4
|
+
export { stubsRoot } from './stubs/main.js';
|
|
4
5
|
export { AllyManager } from './src/ally_manager.js';
|
|
5
|
-
export { defineConfig } from './src/define_config.js';
|
|
6
|
+
export { defineConfig, services } from './src/define_config.js';
|
|
6
7
|
export { RedirectRequest } from './src/redirect_request.js';
|
|
7
8
|
export { Oauth1Driver } from './src/abstract_drivers/oauth1.js';
|
|
8
9
|
export { Oauth2Driver } from './src/abstract_drivers/oauth2.js';
|
|
9
|
-
export { default as driversList } from './src/drivers_collection.js';
|
|
10
|
-
export { stubsRoot } from './stubs/main.js';
|
|
11
|
-
export { configure } from './configure.js';
|
package/build/index.js
CHANGED
|
@@ -6,14 +6,12 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import './src/bindings/types.js';
|
|
10
9
|
export { HttpClient as ApiRequest } from '@poppinss/oauth-client';
|
|
11
10
|
export * as errors from './src/errors.js';
|
|
11
|
+
export { configure } from './configure.js';
|
|
12
|
+
export { stubsRoot } from './stubs/main.js';
|
|
12
13
|
export { AllyManager } from './src/ally_manager.js';
|
|
13
|
-
export { defineConfig } from './src/define_config.js';
|
|
14
|
+
export { defineConfig, services } from './src/define_config.js';
|
|
14
15
|
export { RedirectRequest } from './src/redirect_request.js';
|
|
15
16
|
export { Oauth1Driver } from './src/abstract_drivers/oauth1.js';
|
|
16
17
|
export { Oauth2Driver } from './src/abstract_drivers/oauth2.js';
|
|
17
|
-
export { default as driversList } from './src/drivers_collection.js';
|
|
18
|
-
export { stubsRoot } from './stubs/main.js';
|
|
19
|
-
export { configure } from './configure.js';
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { ApplicationService } from '@adonisjs/core/types';
|
|
2
|
+
import type { AllyService } from '../src/types.js';
|
|
3
|
+
declare module '@adonisjs/core/http' {
|
|
4
|
+
interface HttpContext {
|
|
5
|
+
ally: AllyService;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
9
|
* AllyProvider extends the HTTP context with the "ally" property
|
|
4
10
|
*/
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
9
|
+
import { configProvider } from '@adonisjs/core';
|
|
10
|
+
import { HttpContext } from '@adonisjs/core/http';
|
|
11
|
+
import { RuntimeException } from '@poppinss/utils';
|
|
12
|
+
import { AllyManager } from '../src/ally_manager.js';
|
|
11
13
|
/**
|
|
12
14
|
* AllyProvider extends the HTTP context with the "ally" property
|
|
13
15
|
*/
|
|
@@ -17,8 +19,19 @@ export default class AllyProvider {
|
|
|
17
19
|
this.app = app;
|
|
18
20
|
}
|
|
19
21
|
async boot() {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const allyConfigProvider = this.app.config.get('ally');
|
|
23
|
+
/**
|
|
24
|
+
* Resolve config from the provider
|
|
25
|
+
*/
|
|
26
|
+
const config = await configProvider.resolve(this.app, allyConfigProvider);
|
|
27
|
+
if (!config) {
|
|
28
|
+
throw new RuntimeException('Invalid "config/ally.ts" file. Make sure you are using the "defineConfig" method');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Setup HTTPContext getter
|
|
32
|
+
*/
|
|
33
|
+
HttpContext.getter('ally', function () {
|
|
34
|
+
return new AllyManager(config, this);
|
|
35
|
+
}, true);
|
|
23
36
|
}
|
|
24
37
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Oauth1Client } from '@poppinss/oauth-client';
|
|
2
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import { Oauth1Client } from '@poppinss/oauth-client/oauth1';
|
|
3
3
|
import { AllyUserContract, Oauth1AccessToken, Oauth1DriverConfig, ApiRequestContract, AllyDriverContract, RedirectRequestContract } from '../types.js';
|
|
4
4
|
import { RedirectRequest } from '../redirect_request.js';
|
|
5
5
|
/**
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { Exception } from '@poppinss/utils';
|
|
10
|
-
import { Oauth1Client } from '@poppinss/oauth-client';
|
|
10
|
+
import { Oauth1Client } from '@poppinss/oauth-client/oauth1';
|
|
11
11
|
import * as errors from '../errors.js';
|
|
12
12
|
import { RedirectRequest } from '../redirect_request.js';
|
|
13
13
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Oauth2Client } from '@poppinss/oauth-client';
|
|
2
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import { Oauth2Client } from '@poppinss/oauth-client/oauth2';
|
|
3
3
|
import { AllyUserContract, Oauth2AccessToken, Oauth2DriverConfig, ApiRequestContract, AllyDriverContract, RedirectRequestContract } from '../types.js';
|
|
4
4
|
import { RedirectRequest } from '../redirect_request.js';
|
|
5
5
|
/**
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { Exception } from '@poppinss/utils';
|
|
10
|
-
import { Oauth2Client } from '@poppinss/oauth-client';
|
|
10
|
+
import { Oauth2Client } from '@poppinss/oauth-client/oauth2';
|
|
11
11
|
import * as errors from '../errors.js';
|
|
12
12
|
import { RedirectRequest } from '../redirect_request.js';
|
|
13
13
|
/**
|
package/build/src/debug.d.ts
CHANGED
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ConfigProvider } from '@adonisjs/core/types';
|
|
3
|
+
import type { GoogleDriver } from './drivers/google.js';
|
|
4
|
+
import type { GithubDriver } from './drivers/github.js';
|
|
5
|
+
import type { SpotifyDriver } from './drivers/spotify.js';
|
|
6
|
+
import type { TwitterDriver } from './drivers/twitter.js';
|
|
7
|
+
import type { DiscordDriver } from './drivers/discord.js';
|
|
8
|
+
import type { FacebookDriver } from './drivers/facebook.js';
|
|
9
|
+
import type { LinkedInDriver } from './drivers/linked_in.js';
|
|
10
|
+
import type { GoogleDriverConfig, GithubDriverConfig, SpotifyDriverConfig, DiscordDriverConfig, TwitterDriverConfig, LinkedInDriverConfig, FacebookDriverConfig, AllyManagerDriverFactory } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Shape of config after it has been resolved from
|
|
13
|
+
* the config provider
|
|
14
|
+
*/
|
|
15
|
+
type ResolvedConfig<KnownSocialProviders extends Record<string, AllyManagerDriverFactory | ConfigProvider<AllyManagerDriverFactory>>> = {
|
|
16
|
+
[K in keyof KnownSocialProviders]: KnownSocialProviders[K] extends ConfigProvider<infer A> ? A : KnownSocialProviders[K];
|
|
17
|
+
};
|
|
3
18
|
/**
|
|
4
19
|
* Define config for the ally
|
|
5
20
|
*/
|
|
6
|
-
export declare function defineConfig<KnownSocialProviders extends Record<string,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
export declare function defineConfig<KnownSocialProviders extends Record<string, AllyManagerDriverFactory | ConfigProvider<AllyManagerDriverFactory>>>(config: KnownSocialProviders): ConfigProvider<ResolvedConfig<KnownSocialProviders>>;
|
|
22
|
+
/**
|
|
23
|
+
* Helpers to configure social auth services
|
|
24
|
+
*/
|
|
25
|
+
export declare const services: {
|
|
26
|
+
discord: (config: DiscordDriverConfig) => ConfigProvider<(ctx: HttpContext) => DiscordDriver>;
|
|
27
|
+
facebook: (config: FacebookDriverConfig) => ConfigProvider<(ctx: HttpContext) => FacebookDriver>;
|
|
28
|
+
github: (config: GithubDriverConfig) => ConfigProvider<(ctx: HttpContext) => GithubDriver>;
|
|
29
|
+
google: (config: GoogleDriverConfig) => ConfigProvider<(ctx: HttpContext) => GoogleDriver>;
|
|
30
|
+
linkedin: (config: LinkedInDriverConfig) => ConfigProvider<(ctx: HttpContext) => LinkedInDriver>;
|
|
31
|
+
spotify: (config: SpotifyDriverConfig) => ConfigProvider<(ctx: HttpContext) => SpotifyDriver>;
|
|
32
|
+
twitter: (config: TwitterDriverConfig) => ConfigProvider<(ctx: HttpContext) => TwitterDriver>;
|
|
15
33
|
};
|
|
34
|
+
export {};
|
|
@@ -6,26 +6,70 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import
|
|
9
|
+
import { configProvider } from '@adonisjs/core';
|
|
10
10
|
/**
|
|
11
11
|
* Define config for the ally
|
|
12
12
|
*/
|
|
13
13
|
export function defineConfig(config) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
services,
|
|
29
|
-
driversInUse,
|
|
30
|
-
};
|
|
14
|
+
return configProvider.create(async (app) => {
|
|
15
|
+
const serviceNames = Object.keys(config);
|
|
16
|
+
const services = {};
|
|
17
|
+
for (let serviceName of serviceNames) {
|
|
18
|
+
const service = config[serviceName];
|
|
19
|
+
if (typeof service === 'function') {
|
|
20
|
+
services[serviceName] = service;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
services[serviceName] = await service.resolver(app);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return services;
|
|
27
|
+
});
|
|
31
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Helpers to configure social auth services
|
|
31
|
+
*/
|
|
32
|
+
export const services = {
|
|
33
|
+
discord(config) {
|
|
34
|
+
return configProvider.create(async () => {
|
|
35
|
+
const { DiscordDriver } = await import('./drivers/discord.js');
|
|
36
|
+
return (ctx) => new DiscordDriver(ctx, config);
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
facebook(config) {
|
|
40
|
+
return configProvider.create(async () => {
|
|
41
|
+
const { FacebookDriver } = await import('./drivers/facebook.js');
|
|
42
|
+
return (ctx) => new FacebookDriver(ctx, config);
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
github(config) {
|
|
46
|
+
return configProvider.create(async () => {
|
|
47
|
+
const { GithubDriver } = await import('./drivers/github.js');
|
|
48
|
+
return (ctx) => new GithubDriver(ctx, config);
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
google(config) {
|
|
52
|
+
return configProvider.create(async () => {
|
|
53
|
+
const { GoogleDriver } = await import('./drivers/google.js');
|
|
54
|
+
return (ctx) => new GoogleDriver(ctx, config);
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
linkedin(config) {
|
|
58
|
+
return configProvider.create(async () => {
|
|
59
|
+
const { LinkedInDriver } = await import('./drivers/linked_in.js');
|
|
60
|
+
return (ctx) => new LinkedInDriver(ctx, config);
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
spotify(config) {
|
|
64
|
+
return configProvider.create(async () => {
|
|
65
|
+
const { SpotifyDriver } = await import('./drivers/spotify.js');
|
|
66
|
+
return (ctx) => new SpotifyDriver(ctx, config);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
twitter(config) {
|
|
70
|
+
return configProvider.create(async () => {
|
|
71
|
+
const { TwitterDriver } = await import('./drivers/twitter.js');
|
|
72
|
+
return (ctx) => new TwitterDriver(ctx, config);
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import {
|
|
2
|
+
import type { HttpClient } from '@poppinss/oauth-client';
|
|
3
|
+
import type { DiscordScopes, DiscordToken, ApiRequestContract, DiscordDriverConfig, RedirectRequestContract } from '../types.js';
|
|
3
4
|
import { Oauth2Driver } from '../abstract_drivers/oauth2.js';
|
|
4
5
|
/**
|
|
5
6
|
* Discord driver to login user via Discord
|
|
6
7
|
*/
|
|
7
|
-
export declare class DiscordDriver extends Oauth2Driver<DiscordToken, DiscordScopes>
|
|
8
|
+
export declare class DiscordDriver extends Oauth2Driver<DiscordToken, DiscordScopes> {
|
|
8
9
|
config: DiscordDriverConfig;
|
|
9
10
|
protected accessTokenUrl: string;
|
|
10
11
|
protected authorizeUrl: string;
|
|
@@ -46,7 +47,7 @@ export declare class DiscordDriver extends Oauth2Driver<DiscordToken, DiscordSco
|
|
|
46
47
|
/**
|
|
47
48
|
* Returns the HTTP request with the authorization header set
|
|
48
49
|
*/
|
|
49
|
-
protected getAuthenticatedRequest(url: string, token: string):
|
|
50
|
+
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
|
|
50
51
|
/**
|
|
51
52
|
* Fetches the user info from the Discord API
|
|
52
53
|
* https://discord.com/developers/docs/resources/user#get-current-user
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { HttpClient } from '@poppinss/oauth-client';
|
|
1
2
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import { FacebookToken, FacebookScopes, LiteralStringUnion, ApiRequestContract, FacebookDriverConfig, FacebookProfileFields,
|
|
3
|
+
import type { FacebookToken, FacebookScopes, LiteralStringUnion, ApiRequestContract, FacebookDriverConfig, FacebookProfileFields, RedirectRequestContract } from '../types.js';
|
|
3
4
|
import { Oauth2Driver } from '../abstract_drivers/oauth2.js';
|
|
4
5
|
/**
|
|
5
6
|
* Facebook driver to login user via Facebook
|
|
6
7
|
*/
|
|
7
|
-
export declare class FacebookDriver extends Oauth2Driver<FacebookToken, FacebookScopes>
|
|
8
|
+
export declare class FacebookDriver extends Oauth2Driver<FacebookToken, FacebookScopes> {
|
|
8
9
|
config: FacebookDriverConfig;
|
|
9
10
|
protected accessTokenUrl: string;
|
|
10
11
|
protected authorizeUrl: string;
|
|
@@ -46,7 +47,7 @@ export declare class FacebookDriver extends Oauth2Driver<FacebookToken, Facebook
|
|
|
46
47
|
/**
|
|
47
48
|
* Returns the HTTP request with the authorization header set
|
|
48
49
|
*/
|
|
49
|
-
protected getAuthenticatedRequest(url: string, token: string):
|
|
50
|
+
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
|
|
50
51
|
/**
|
|
51
52
|
* Fetches the user info from the Facebook API
|
|
52
53
|
* https://developers.facebook.com/docs/graph-api/reference/user/
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import {
|
|
2
|
+
import type { HttpClient } from '@poppinss/oauth-client';
|
|
3
|
+
import type { GithubToken, GithubScopes, GithubDriverConfig, ApiRequestContract, RedirectRequestContract } from '../types.js';
|
|
3
4
|
import { Oauth2Driver } from '../abstract_drivers/oauth2.js';
|
|
4
5
|
/**
|
|
5
6
|
* Github driver to login user via Github
|
|
6
7
|
*/
|
|
7
|
-
export declare class GithubDriver extends Oauth2Driver<GithubToken, GithubScopes>
|
|
8
|
+
export declare class GithubDriver extends Oauth2Driver<GithubToken, GithubScopes> {
|
|
8
9
|
config: GithubDriverConfig;
|
|
9
10
|
protected accessTokenUrl: string;
|
|
10
11
|
protected authorizeUrl: string;
|
|
@@ -47,7 +48,7 @@ export declare class GithubDriver extends Oauth2Driver<GithubToken, GithubScopes
|
|
|
47
48
|
/**
|
|
48
49
|
* Returns the HTTP request with the authorization header set
|
|
49
50
|
*/
|
|
50
|
-
protected getAuthenticatedRequest(url: string, token: string):
|
|
51
|
+
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
|
|
51
52
|
/**
|
|
52
53
|
* Fetches the user info from the Github API
|
|
53
54
|
* https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import {
|
|
2
|
+
import type { HttpClient } from '@poppinss/oauth-client';
|
|
3
|
+
import type { GoogleToken, GoogleScopes, GoogleDriverConfig, ApiRequestContract, RedirectRequestContract } from '../types.js';
|
|
3
4
|
import { Oauth2Driver } from '../abstract_drivers/oauth2.js';
|
|
4
5
|
/**
|
|
5
6
|
* Google driver to login user via Google
|
|
6
7
|
*/
|
|
7
|
-
export declare class GoogleDriver extends Oauth2Driver<GoogleToken, GoogleScopes>
|
|
8
|
+
export declare class GoogleDriver extends Oauth2Driver<GoogleToken, GoogleScopes> {
|
|
8
9
|
config: GoogleDriverConfig;
|
|
9
10
|
protected accessTokenUrl: string;
|
|
10
11
|
protected authorizeUrl: string;
|
|
@@ -42,7 +43,7 @@ export declare class GoogleDriver extends Oauth2Driver<GoogleToken, GoogleScopes
|
|
|
42
43
|
/**
|
|
43
44
|
* Returns the HTTP request with the authorization header set
|
|
44
45
|
*/
|
|
45
|
-
protected getAuthenticatedRequest(url: string, token: string):
|
|
46
|
+
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
|
|
46
47
|
/**
|
|
47
48
|
* Fetches the user info from the Google API
|
|
48
49
|
*/
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import {
|
|
2
|
+
import type { HttpClient } from '@poppinss/oauth-client';
|
|
3
|
+
import type { LinkedInToken, LinkedInScopes, ApiRequestContract, LinkedInDriverConfig, RedirectRequestContract } from '../types.js';
|
|
3
4
|
import { Oauth2Driver } from '../abstract_drivers/oauth2.js';
|
|
4
5
|
/**
|
|
5
6
|
* LinkedIn driver to login user via LinkedIn
|
|
6
7
|
*/
|
|
7
|
-
export declare class LinkedInDriver extends Oauth2Driver<LinkedInToken, LinkedInScopes>
|
|
8
|
+
export declare class LinkedInDriver extends Oauth2Driver<LinkedInToken, LinkedInScopes> {
|
|
8
9
|
config: LinkedInDriverConfig;
|
|
9
10
|
protected accessTokenUrl: string;
|
|
10
11
|
protected authorizeUrl: string;
|
|
@@ -43,7 +44,7 @@ export declare class LinkedInDriver extends Oauth2Driver<LinkedInToken, LinkedIn
|
|
|
43
44
|
/**
|
|
44
45
|
* Returns the HTTP request with the authorization header set
|
|
45
46
|
*/
|
|
46
|
-
protected getAuthenticatedRequest(url: string, token: string):
|
|
47
|
+
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
|
|
47
48
|
/**
|
|
48
49
|
* Fetches the user info from the LinkedIn API
|
|
49
50
|
*/
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import {
|
|
2
|
+
import type { HttpClient } from '@poppinss/oauth-client';
|
|
3
|
+
import type { SpotifyScopes, SpotifyToken, ApiRequestContract, SpotifyDriverConfig, RedirectRequestContract } from '../types.js';
|
|
3
4
|
import { Oauth2Driver } from '../abstract_drivers/oauth2.js';
|
|
4
5
|
/**
|
|
5
6
|
* Spotify driver to login user via Spotify
|
|
6
7
|
*/
|
|
7
|
-
export declare class SpotifyDriver extends Oauth2Driver<SpotifyToken, SpotifyScopes>
|
|
8
|
+
export declare class SpotifyDriver extends Oauth2Driver<SpotifyToken, SpotifyScopes> {
|
|
8
9
|
config: SpotifyDriverConfig;
|
|
9
10
|
protected accessTokenUrl: string;
|
|
10
11
|
protected authorizeUrl: string;
|
|
@@ -42,7 +43,7 @@ export declare class SpotifyDriver extends Oauth2Driver<SpotifyToken, SpotifySco
|
|
|
42
43
|
/**
|
|
43
44
|
* Returns the HTTP request with the authorization header set
|
|
44
45
|
*/
|
|
45
|
-
protected getAuthenticatedRequest(url: string, token: string):
|
|
46
|
+
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
|
|
46
47
|
/**
|
|
47
48
|
* Fetches the user info from the Spotify API
|
|
48
49
|
* https://discord.com/developers/docs/resources/user#get-current-user
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import { TwitterToken, AllyUserContract, ApiRequestContract, TwitterDriverConfig
|
|
2
|
+
import { TwitterToken, AllyUserContract, ApiRequestContract, TwitterDriverConfig } from '../types.js';
|
|
3
3
|
import { Oauth1Driver } from '../abstract_drivers/oauth1.js';
|
|
4
4
|
/**
|
|
5
5
|
* Twitter driver to login user via twitter
|
|
6
6
|
*/
|
|
7
|
-
export declare class TwitterDriver extends Oauth1Driver<TwitterToken, string>
|
|
7
|
+
export declare class TwitterDriver extends Oauth1Driver<TwitterToken, string> {
|
|
8
8
|
protected ctx: HttpContext;
|
|
9
9
|
config: TwitterDriverConfig;
|
|
10
10
|
protected requestTokenUrl: string;
|
package/build/src/types.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import {
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import type { ConfigProvider } from '@adonisjs/core/types';
|
|
3
|
+
import type { Oauth2AccessToken, Oauth1RequestToken, Oauth1AccessToken, Oauth1ClientConfig, Oauth2ClientConfig, ApiRequestContract, RedirectRequestContract as ClientRequestContract } from '@poppinss/oauth-client/types';
|
|
4
|
+
import type { AllyManager } from './ally_manager.js';
|
|
3
5
|
export type { Oauth2AccessToken };
|
|
4
6
|
export type { Oauth1AccessToken };
|
|
5
7
|
export type { Oauth1RequestToken };
|
|
@@ -115,6 +117,11 @@ export interface AllyDriverContract<Token extends Oauth2AccessToken | Oauth1Acce
|
|
|
115
117
|
secret: string;
|
|
116
118
|
}>>;
|
|
117
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* The manager driver factory method is called by the AllyManager to create
|
|
122
|
+
* an instance of a driver during an HTTP request
|
|
123
|
+
*/
|
|
124
|
+
export type AllyManagerDriverFactory = (ctx: HttpContext) => AllyDriverContract<any, any>;
|
|
118
125
|
/**
|
|
119
126
|
* ----------------------------------------
|
|
120
127
|
* Discord driver
|
|
@@ -147,9 +154,6 @@ export type DiscordDriverConfig = Oauth2ClientConfig & {
|
|
|
147
154
|
disableGuildSelect?: boolean;
|
|
148
155
|
permissions?: number;
|
|
149
156
|
};
|
|
150
|
-
export interface DiscordDriverContract extends AllyDriverContract<DiscordToken, DiscordScopes> {
|
|
151
|
-
version: 'oauth2';
|
|
152
|
-
}
|
|
153
157
|
/**
|
|
154
158
|
* ----------------------------------------
|
|
155
159
|
* Github driver
|
|
@@ -178,9 +182,6 @@ export type GithubDriverConfig = Oauth2ClientConfig & {
|
|
|
178
182
|
userInfoUrl?: string;
|
|
179
183
|
userEmailUrl?: string;
|
|
180
184
|
};
|
|
181
|
-
export interface GithubDriverContract extends AllyDriverContract<GithubToken, GithubScopes> {
|
|
182
|
-
version: 'oauth2';
|
|
183
|
-
}
|
|
184
185
|
/**
|
|
185
186
|
* ----------------------------------------
|
|
186
187
|
* Twitter driver
|
|
@@ -201,9 +202,6 @@ export type TwitterToken = {
|
|
|
201
202
|
export type TwitterDriverConfig = Oauth1ClientConfig & {
|
|
202
203
|
userInfoUrl?: string;
|
|
203
204
|
};
|
|
204
|
-
export interface TwitterDriverContract extends AllyDriverContract<TwitterToken, string> {
|
|
205
|
-
version: 'oauth1';
|
|
206
|
-
}
|
|
207
205
|
/**
|
|
208
206
|
* ----------------------------------------
|
|
209
207
|
* Google driver
|
|
@@ -242,9 +240,6 @@ export type GoogleDriverConfig = Oauth2ClientConfig & {
|
|
|
242
240
|
hostedDomain?: string;
|
|
243
241
|
display?: 'page' | 'popup' | 'touch' | 'wrap';
|
|
244
242
|
};
|
|
245
|
-
export interface GoogleDriverContract extends AllyDriverContract<GoogleToken, GoogleScopes> {
|
|
246
|
-
version: 'oauth2';
|
|
247
|
-
}
|
|
248
243
|
/**
|
|
249
244
|
* ----------------------------------------
|
|
250
245
|
* LinkedIn driver
|
|
@@ -278,9 +273,6 @@ export type LinkedInDriverConfig = Oauth2ClientConfig & {
|
|
|
278
273
|
*/
|
|
279
274
|
scopes?: LiteralStringUnion<LinkedInScopes>[];
|
|
280
275
|
};
|
|
281
|
-
export interface LinkedInDriverContract extends AllyDriverContract<LinkedInToken, LinkedInScopes> {
|
|
282
|
-
version: 'oauth2';
|
|
283
|
-
}
|
|
284
276
|
/**
|
|
285
277
|
* ----------------------------------------
|
|
286
278
|
* Facebook driver
|
|
@@ -320,9 +312,6 @@ export type FacebookDriverConfig = Oauth2ClientConfig & {
|
|
|
320
312
|
display?: string;
|
|
321
313
|
authType?: string;
|
|
322
314
|
};
|
|
323
|
-
export interface FacebookDriverContract extends AllyDriverContract<FacebookToken, FacebookScopes> {
|
|
324
|
-
version: 'oauth2';
|
|
325
|
-
}
|
|
326
315
|
/**
|
|
327
316
|
* ----------------------------------------
|
|
328
317
|
* Spotify driver
|
|
@@ -350,36 +339,18 @@ export type SpotifyDriverConfig = Oauth2ClientConfig & {
|
|
|
350
339
|
scopes?: LiteralStringUnion<SpotifyScopes>[];
|
|
351
340
|
showDialog?: boolean;
|
|
352
341
|
};
|
|
353
|
-
export interface SpotifyDriverContract extends AllyDriverContract<SpotifyToken, SpotifyScopes> {
|
|
354
|
-
version: 'oauth2';
|
|
355
|
-
}
|
|
356
342
|
/**
|
|
357
343
|
* END OF DRIVERS
|
|
358
344
|
*/
|
|
359
|
-
/**
|
|
360
|
-
* List of known ally drivers. The list can be extended using
|
|
361
|
-
* declaration merging
|
|
362
|
-
*/
|
|
363
|
-
export interface AllyDriversList {
|
|
364
|
-
discord: (config: DiscordDriverConfig, ctx: HttpContext) => DiscordDriverContract;
|
|
365
|
-
facebook: (config: FacebookDriverConfig, ctx: HttpContext) => FacebookDriverContract;
|
|
366
|
-
github: (config: GithubDriverConfig, ctx: HttpContext) => GithubDriverContract;
|
|
367
|
-
google: (config: GoogleDriverConfig, ctx: HttpContext) => GoogleDriverContract;
|
|
368
|
-
linkedin: (config: LinkedInDriverConfig, ctx: HttpContext) => LinkedInDriverContract;
|
|
369
|
-
spotify: (config: SpotifyDriverConfig, ctx: HttpContext) => SpotifyDriverContract;
|
|
370
|
-
twitter: (config: TwitterDriverConfig, ctx: HttpContext) => TwitterDriverContract;
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* The manager driver factory method is called by the AllyManager to create
|
|
374
|
-
* an instance of a driver during an HTTP request
|
|
375
|
-
*/
|
|
376
|
-
export type AllyManagerDriverFactory = (ctx: HttpContext) => AllyDriverContract<any, any>;
|
|
377
345
|
/**
|
|
378
346
|
* Social providers are inferred inside the user application
|
|
379
347
|
* from the config file
|
|
380
348
|
*/
|
|
381
349
|
export interface SocialProviders {
|
|
382
350
|
}
|
|
383
|
-
export type InferSocialProviders<T extends
|
|
384
|
-
|
|
385
|
-
|
|
351
|
+
export type InferSocialProviders<T extends ConfigProvider<Record<string, AllyManagerDriverFactory>>> = Awaited<ReturnType<T['resolver']>>;
|
|
352
|
+
/**
|
|
353
|
+
* Ally service is shared with the HTTP context
|
|
354
|
+
*/
|
|
355
|
+
export interface AllyService extends AllyManager<SocialProviders extends Record<string, AllyManagerDriverFactory> ? SocialProviders : never> {
|
|
356
|
+
}
|
package/build/stubs/config.stub
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
to:
|
|
3
|
-
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.configPath('ally.ts') })
|
|
3
|
+
}}}
|
|
4
4
|
import env from '#start/env'
|
|
5
|
-
import { defineConfig } from '@adonisjs/ally'
|
|
5
|
+
import { defineConfig, services } from '@adonisjs/ally'
|
|
6
6
|
|
|
7
7
|
const allyConfig = defineConfig({
|
|
8
8
|
{{#each providers as provider}}
|
|
9
|
-
{{provider.provider}}: {
|
|
10
|
-
driver: '{{provider.provider}}',
|
|
9
|
+
{{provider.provider}}: services.{{provider.provider}}({
|
|
11
10
|
clientId: env.get('{{provider.envPrefix}}_CLIENT_ID'),
|
|
12
11
|
clientSecret: env.get('{{provider.envPrefix}}_CLIENT_SECRET'),
|
|
13
12
|
callbackUrl: '',
|
|
14
|
-
},
|
|
13
|
+
}),
|
|
15
14
|
{{/each}}
|
|
16
15
|
})
|
|
17
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/ally",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-6",
|
|
4
4
|
"description": "Social authentication provider for AdonisJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "build/index.js",
|
|
@@ -47,38 +47,38 @@
|
|
|
47
47
|
"author": "adonisjs,virk",
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@adonisjs/assembler": "^6.1.3-
|
|
51
|
-
"@adonisjs/core": "^6.1.5-
|
|
50
|
+
"@adonisjs/assembler": "^6.1.3-25",
|
|
51
|
+
"@adonisjs/core": "^6.1.5-29",
|
|
52
52
|
"@adonisjs/eslint-config": "^1.1.8",
|
|
53
53
|
"@adonisjs/prettier-config": "^1.1.8",
|
|
54
54
|
"@adonisjs/tsconfig": "^1.1.8",
|
|
55
|
-
"@commitlint/cli": "^17.
|
|
56
|
-
"@commitlint/config-conventional": "^17.
|
|
57
|
-
"@japa/assert": "^2.0.0
|
|
58
|
-
"@japa/expect-type": "^2.0.0
|
|
59
|
-
"@japa/file-system": "^2.0.0
|
|
60
|
-
"@japa/runner": "^3.0.
|
|
61
|
-
"@swc/core": "
|
|
62
|
-
"@types/node": "^20.
|
|
55
|
+
"@commitlint/cli": "^17.8.0",
|
|
56
|
+
"@commitlint/config-conventional": "^17.8.0",
|
|
57
|
+
"@japa/assert": "^2.0.0",
|
|
58
|
+
"@japa/expect-type": "^2.0.0",
|
|
59
|
+
"@japa/file-system": "^2.0.0",
|
|
60
|
+
"@japa/runner": "^3.0.4",
|
|
61
|
+
"@swc/core": "1.3.82",
|
|
62
|
+
"@types/node": "^20.8.7",
|
|
63
63
|
"c8": "^8.0.1",
|
|
64
64
|
"copyfiles": "^2.4.1",
|
|
65
|
-
"del-cli": "^5.
|
|
65
|
+
"del-cli": "^5.1.0",
|
|
66
66
|
"dotenv": "^16.3.1",
|
|
67
|
-
"eslint": "^8.
|
|
67
|
+
"eslint": "^8.51.0",
|
|
68
68
|
"github-label-sync": "^2.3.1",
|
|
69
69
|
"husky": "^8.0.3",
|
|
70
|
-
"nock": "^13.3.
|
|
70
|
+
"nock": "^13.3.4",
|
|
71
71
|
"np": "^8.0.4",
|
|
72
|
-
"prettier": "^3.0.
|
|
72
|
+
"prettier": "^3.0.3",
|
|
73
73
|
"ts-node": "^10.9.1",
|
|
74
|
-
"typescript": "^5.
|
|
74
|
+
"typescript": "^5.2.2"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@poppinss/oauth-client": "^5.1.0
|
|
78
|
-
"@poppinss/utils": "^6.5.0
|
|
77
|
+
"@poppinss/oauth-client": "^5.1.0",
|
|
78
|
+
"@poppinss/utils": "^6.5.0"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
|
-
"@adonisjs/core": "^6.1.5-
|
|
81
|
+
"@adonisjs/core": "^6.1.5-29"
|
|
82
82
|
},
|
|
83
83
|
"repository": {
|
|
84
84
|
"type": "git",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/ally
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { HttpContext } from '@adonisjs/core/http';
|
|
10
|
-
import './types.js';
|
|
11
|
-
import { AllyManager } from '../ally_manager.js';
|
|
12
|
-
/**
|
|
13
|
-
* Extends HttpContext class with the ally getter
|
|
14
|
-
*/
|
|
15
|
-
export function extendHttpContext(config) {
|
|
16
|
-
HttpContext.getter('ally', function () {
|
|
17
|
-
return new AllyManager(config, this);
|
|
18
|
-
}, true);
|
|
19
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { AllyManager } from '../ally_manager.js';
|
|
2
|
-
import type { AllyManagerDriverFactory, SocialProviders } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* In order for types to get picked up, this module must get
|
|
5
|
-
* imported by TypeScript. Therefore, we export this module
|
|
6
|
-
* from the package entrypoint
|
|
7
|
-
*/
|
|
8
|
-
declare module '@adonisjs/core/http' {
|
|
9
|
-
interface HttpContext {
|
|
10
|
-
ally: AllyManager<SocialProviders extends Record<string, AllyManagerDriverFactory> ? SocialProviders : never>;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export declare const twitter: {
|
|
2
|
-
REQUEST_TOKEN_URL: string;
|
|
3
|
-
AUTHORIZE_URL: string;
|
|
4
|
-
ACCESS_TOKEN_URL: string;
|
|
5
|
-
};
|
|
6
|
-
export declare const github: {
|
|
7
|
-
AUTHORIZE_URL: string;
|
|
8
|
-
ACCESS_TOKEN_URL: string;
|
|
9
|
-
USER_INFO_URL: string;
|
|
10
|
-
USER_EMAIL_URL: string;
|
|
11
|
-
};
|
|
12
|
-
export declare const google: {
|
|
13
|
-
AUTHORIZE_URL: string;
|
|
14
|
-
ACCESS_TOKEN_URL: string;
|
|
15
|
-
USER_INFO_URL: string;
|
|
16
|
-
};
|
|
17
|
-
export declare const gitlab: {
|
|
18
|
-
AUTHORIZE_URL: string;
|
|
19
|
-
ACCESS_TOKEN_URL: string;
|
|
20
|
-
};
|
|
21
|
-
export declare const linkedin: {
|
|
22
|
-
AUTHORIZE_URL: string;
|
|
23
|
-
ACCESS_TOKEN_URL: string;
|
|
24
|
-
};
|
|
25
|
-
export declare const patreon: {
|
|
26
|
-
AUTHORIZE_URL: string;
|
|
27
|
-
ACCESS_TOKEN_URL: string;
|
|
28
|
-
};
|
|
29
|
-
export declare const discord: {
|
|
30
|
-
AUTHORIZE_URL: string;
|
|
31
|
-
ACCESS_TOKEN_URL: string;
|
|
32
|
-
USER_INFO_URL: string;
|
|
33
|
-
};
|
|
34
|
-
export declare const microsoft: {
|
|
35
|
-
AUTHORIZE_URL: string;
|
|
36
|
-
ACCESS_TOKEN_URL: string;
|
|
37
|
-
};
|
|
38
|
-
export declare const bitbucket: {
|
|
39
|
-
AUTHORIZE_URL: string;
|
|
40
|
-
ACCESS_TOKEN_URL: string;
|
|
41
|
-
};
|
|
42
|
-
export declare const facebook: {
|
|
43
|
-
AUTHORIZE_URL: string;
|
|
44
|
-
ACCESS_TOKEN_URL: string;
|
|
45
|
-
};
|
|
46
|
-
export declare const spotify: {
|
|
47
|
-
AUTHORIZE_URL: string;
|
|
48
|
-
ACCESS_TOKEN_URL: string;
|
|
49
|
-
USER_INFO_URL: string;
|
|
50
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/ally
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
export const twitter = {
|
|
10
|
-
REQUEST_TOKEN_URL: 'https://api.twitter.com/oauth/request_token',
|
|
11
|
-
AUTHORIZE_URL: 'https://api.twitter.com/oauth/authenticate',
|
|
12
|
-
ACCESS_TOKEN_URL: 'https://api.twitter.com/oauth/access_token',
|
|
13
|
-
};
|
|
14
|
-
export const github = {
|
|
15
|
-
AUTHORIZE_URL: 'https://github.com/login/oauth/authorize',
|
|
16
|
-
ACCESS_TOKEN_URL: 'https://github.com/login/oauth/access_token',
|
|
17
|
-
USER_INFO_URL: 'https://api.github.com/user',
|
|
18
|
-
USER_EMAIL_URL: 'https://api.github.com/user/emails',
|
|
19
|
-
};
|
|
20
|
-
export const google = {
|
|
21
|
-
AUTHORIZE_URL: 'https://accounts.google.com/o/oauth2/v2/auth',
|
|
22
|
-
ACCESS_TOKEN_URL: 'https://oauth2.googleapis.com/token',
|
|
23
|
-
USER_INFO_URL: 'https://www.googleapis.com/oauth2/v3/userinfo',
|
|
24
|
-
};
|
|
25
|
-
export const gitlab = {
|
|
26
|
-
AUTHORIZE_URL: 'https://gitlab.com/oauth/authorize',
|
|
27
|
-
ACCESS_TOKEN_URL: 'https://gitlab.com/oauth/token',
|
|
28
|
-
};
|
|
29
|
-
export const linkedin = {
|
|
30
|
-
AUTHORIZE_URL: 'https://www.linkedin.com/oauth/v2/authorization',
|
|
31
|
-
ACCESS_TOKEN_URL: 'https://www.linkedin.com/oauth/v2/accessToken',
|
|
32
|
-
};
|
|
33
|
-
export const patreon = {
|
|
34
|
-
AUTHORIZE_URL: 'https://www.patreon.com/oauth2/authorize',
|
|
35
|
-
ACCESS_TOKEN_URL: 'https://www.patreon.com/api/oauth2/token',
|
|
36
|
-
};
|
|
37
|
-
export const discord = {
|
|
38
|
-
AUTHORIZE_URL: 'https://discord.com/api/oauth2/authorize',
|
|
39
|
-
ACCESS_TOKEN_URL: 'https://discord.com/api/oauth2/token',
|
|
40
|
-
USER_INFO_URL: 'https://discord.com/api/users/@me',
|
|
41
|
-
};
|
|
42
|
-
export const microsoft = {
|
|
43
|
-
AUTHORIZE_URL: 'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize',
|
|
44
|
-
ACCESS_TOKEN_URL: 'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token',
|
|
45
|
-
};
|
|
46
|
-
export const bitbucket = {
|
|
47
|
-
AUTHORIZE_URL: 'https://bitbucket.org/site/oauth2/authorize',
|
|
48
|
-
ACCESS_TOKEN_URL: 'https://bitbucket.org/site/oauth2/access_token',
|
|
49
|
-
};
|
|
50
|
-
export const facebook = {
|
|
51
|
-
AUTHORIZE_URL: 'https://www.facebook.com/v10.0/dialog/oauth',
|
|
52
|
-
ACCESS_TOKEN_URL: 'https://graph.facebook.com/v10.0/dialog/oauth/access_token',
|
|
53
|
-
};
|
|
54
|
-
export const spotify = {
|
|
55
|
-
AUTHORIZE_URL: 'https://accounts.spotify.com/authorize',
|
|
56
|
-
ACCESS_TOKEN_URL: 'https://accounts.spotify.com/api/token',
|
|
57
|
-
USER_INFO_URL: 'https://api.spotify.com/v1/me',
|
|
58
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import type { AllyDriversList } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* A global collection of ally drivers.
|
|
5
|
-
*/
|
|
6
|
-
declare class AllyDriversCollection {
|
|
7
|
-
registerBundledDrivers(drivers: Set<keyof AllyDriversList>): Promise<void>;
|
|
8
|
-
/**
|
|
9
|
-
* List of registered drivers
|
|
10
|
-
*/
|
|
11
|
-
list: Partial<AllyDriversList>;
|
|
12
|
-
/**
|
|
13
|
-
* Extend drivers collection and add a custom
|
|
14
|
-
* driver to it.
|
|
15
|
-
*/
|
|
16
|
-
extend<Name extends keyof AllyDriversList>(driverName: Name, factoryCallback: AllyDriversList[Name]): this;
|
|
17
|
-
/**
|
|
18
|
-
* Creates the driver instance with config
|
|
19
|
-
*/
|
|
20
|
-
create<Name extends keyof AllyDriversList>(name: Name, config: Parameters<AllyDriversList[Name]>[0], ctx: HttpContext): ReturnType<AllyDriversList[Name]>;
|
|
21
|
-
}
|
|
22
|
-
declare const allyDriversCollection: AllyDriversCollection;
|
|
23
|
-
export default allyDriversCollection;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/ally
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { RuntimeException } from '@poppinss/utils';
|
|
10
|
-
import debug from './debug.js';
|
|
11
|
-
/**
|
|
12
|
-
* A global collection of ally drivers.
|
|
13
|
-
*/
|
|
14
|
-
class AllyDriversCollection {
|
|
15
|
-
async registerBundledDrivers(drivers) {
|
|
16
|
-
debug('drivers in use %O', drivers);
|
|
17
|
-
if (drivers.has('discord') && !this.list['discord']) {
|
|
18
|
-
const { DiscordDriver } = await import('../src/drivers/discord.js');
|
|
19
|
-
this.extend('discord', (config, ctx) => new DiscordDriver(ctx, config));
|
|
20
|
-
}
|
|
21
|
-
if (drivers.has('facebook') && !this.list['facebook']) {
|
|
22
|
-
const { FacebookDriver } = await import('../src/drivers/facebook.js');
|
|
23
|
-
this.extend('facebook', (config, ctx) => new FacebookDriver(ctx, config));
|
|
24
|
-
}
|
|
25
|
-
if (drivers.has('github') && !this.list['github']) {
|
|
26
|
-
const { GithubDriver } = await import('../src/drivers/github.js');
|
|
27
|
-
this.extend('github', (config, ctx) => new GithubDriver(ctx, config));
|
|
28
|
-
}
|
|
29
|
-
if (drivers.has('google') && !this.list['google']) {
|
|
30
|
-
const { GoogleDriver } = await import('../src/drivers/google.js');
|
|
31
|
-
this.extend('google', (config, ctx) => new GoogleDriver(ctx, config));
|
|
32
|
-
}
|
|
33
|
-
if (drivers.has('linkedin') && !this.list['linkedin']) {
|
|
34
|
-
const { LinkedInDriver } = await import('../src/drivers/linked_in.js');
|
|
35
|
-
this.extend('linkedin', (config, ctx) => new LinkedInDriver(ctx, config));
|
|
36
|
-
}
|
|
37
|
-
if (drivers.has('spotify') && !this.list['spotify']) {
|
|
38
|
-
const { SpotifyDriver } = await import('../src/drivers/spotify.js');
|
|
39
|
-
this.extend('spotify', (config, ctx) => new SpotifyDriver(ctx, config));
|
|
40
|
-
}
|
|
41
|
-
if (drivers.has('twitter') && !this.list['twitter']) {
|
|
42
|
-
const { TwitterDriver } = await import('../src/drivers/twitter.js');
|
|
43
|
-
this.extend('twitter', (config, ctx) => new TwitterDriver(ctx, config));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* List of registered drivers
|
|
48
|
-
*/
|
|
49
|
-
list = {};
|
|
50
|
-
/**
|
|
51
|
-
* Extend drivers collection and add a custom
|
|
52
|
-
* driver to it.
|
|
53
|
-
*/
|
|
54
|
-
extend(driverName, factoryCallback) {
|
|
55
|
-
debug('registering %s driver', driverName);
|
|
56
|
-
this.list[driverName] = factoryCallback;
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Creates the driver instance with config
|
|
61
|
-
*/
|
|
62
|
-
create(name, config, ctx) {
|
|
63
|
-
const driverFactory = this.list[name];
|
|
64
|
-
if (!driverFactory) {
|
|
65
|
-
throw new RuntimeException(`Unknown ally driver "${String(name)}". Make sure the driver is registered`);
|
|
66
|
-
}
|
|
67
|
-
debug('creating instance of %s driver', name);
|
|
68
|
-
return driverFactory(config, ctx);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const allyDriversCollection = new AllyDriversCollection();
|
|
72
|
-
export default allyDriversCollection;
|