@adonisjs/ally 5.0.0-0 → 5.0.0-2
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/configure.js +20 -2
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/providers/ally_provider.d.ts +1 -1
- package/build/providers/ally_provider.js +4 -1
- package/build/src/abstract_drivers/oauth1.js +1 -1
- package/build/src/abstract_drivers/oauth2.js +1 -1
- package/build/src/bindings/http_context.d.ts +2 -2
- package/build/src/debug.d.ts +3 -0
- package/build/src/debug.js +10 -0
- package/build/src/define_config.d.ts +4 -1
- package/build/src/define_config.js +8 -3
- package/build/src/drivers_collection.d.ts +4 -0
- package/build/src/drivers_collection.js +38 -16
- package/build/src/types.d.ts +3 -1
- package/build/stubs/config.stub +17 -2
- package/package.json +11 -8
- package/build/stubs/types.stub +0 -12
- /package/build/src/{exceptions.d.ts → errors.d.ts} +0 -0
- /package/build/src/{exceptions.js → errors.js} +0 -0
package/build/configure.js
CHANGED
|
@@ -10,9 +10,27 @@
|
|
|
10
10
|
* Configures the package
|
|
11
11
|
*/
|
|
12
12
|
export async function configure(command) {
|
|
13
|
-
await command.
|
|
14
|
-
|
|
13
|
+
const providers = await command.prompt.multiple('Select the social auth providers you plan to use', ['discord', 'facebook', 'github', 'google', 'linkedin', 'spotify', 'twitter']);
|
|
14
|
+
/**
|
|
15
|
+
* Publish config file
|
|
16
|
+
*/
|
|
17
|
+
await command.publishStub('config.stub', {
|
|
18
|
+
providers: providers.map((provider) => {
|
|
19
|
+
return { provider, envPrefix: provider.toUpperCase() };
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Publish provider
|
|
24
|
+
*/
|
|
15
25
|
await command.updateRcFile((rcFile) => {
|
|
16
26
|
rcFile.addProvider('@adonisjs/ally/ally_provider');
|
|
17
27
|
});
|
|
28
|
+
/**
|
|
29
|
+
* Define env variables for the selected providers
|
|
30
|
+
*/
|
|
31
|
+
await command.defineEnvVariables(providers.reduce((result, provider) => {
|
|
32
|
+
result[`${provider.toUpperCase()}_CLIENT_ID`] = '';
|
|
33
|
+
result[`${provider.toUpperCase()}_CLIENT_SECRET`] = '';
|
|
34
|
+
return result;
|
|
35
|
+
}, {}));
|
|
18
36
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './src/bindings/types.js';
|
|
2
2
|
export { HttpClient as ApiRequest } from '@poppinss/oauth-client';
|
|
3
|
-
export * as errors from './src/
|
|
3
|
+
export * as errors from './src/errors.js';
|
|
4
4
|
export { AllyManager } from './src/ally_manager.js';
|
|
5
5
|
export { defineConfig } from './src/define_config.js';
|
|
6
6
|
export { RedirectRequest } from './src/redirect_request.js';
|
package/build/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import './src/bindings/types.js';
|
|
10
10
|
export { HttpClient as ApiRequest } from '@poppinss/oauth-client';
|
|
11
|
-
export * as errors from './src/
|
|
11
|
+
export * as errors from './src/errors.js';
|
|
12
12
|
export { AllyManager } from './src/ally_manager.js';
|
|
13
13
|
export { defineConfig } from './src/define_config.js';
|
|
14
14
|
export { RedirectRequest } from './src/redirect_request.js';
|
|
@@ -6,6 +6,7 @@
|
|
|
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 driversList from '../src/drivers_collection.js';
|
|
9
10
|
import { extendHttpContext } from '../src/bindings/http_context.js';
|
|
10
11
|
/**
|
|
11
12
|
* AllyProvider extends the HTTP context with the "ally" property
|
|
@@ -16,6 +17,8 @@ export default class AllyProvider {
|
|
|
16
17
|
this.app = app;
|
|
17
18
|
}
|
|
18
19
|
async boot() {
|
|
19
|
-
|
|
20
|
+
const config = this.app.config.get('ally');
|
|
21
|
+
extendHttpContext(config.services);
|
|
22
|
+
await driversList.registerBundledDrivers(config.driversInUse);
|
|
20
23
|
}
|
|
21
24
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Exception } from '@poppinss/utils';
|
|
10
10
|
import { Oauth1Client } from '@poppinss/oauth-client';
|
|
11
|
-
import * as errors from '../
|
|
11
|
+
import * as errors from '../errors.js';
|
|
12
12
|
import { RedirectRequest } from '../redirect_request.js';
|
|
13
13
|
/**
|
|
14
14
|
* Abstract implementation for an Oauth1 driver
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Exception } from '@poppinss/utils';
|
|
10
10
|
import { Oauth2Client } from '@poppinss/oauth-client';
|
|
11
|
-
import * as errors from '../
|
|
11
|
+
import * as errors from '../errors.js';
|
|
12
12
|
import { RedirectRequest } from '../redirect_request.js';
|
|
13
13
|
/**
|
|
14
14
|
* Abstract implementation for an Oauth2 driver
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './types.js';
|
|
2
|
-
import { AllyManagerDriverFactory
|
|
2
|
+
import { AllyManagerDriverFactory } from '../types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Extends HttpContext class with the ally getter
|
|
5
5
|
*/
|
|
6
|
-
export declare function extendHttpContext(config:
|
|
6
|
+
export declare function extendHttpContext(config: Record<string, AllyManagerDriverFactory>): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
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 { debuglog } from 'node:util';
|
|
10
|
+
export default debuglog('adonisjs:ally');
|
|
@@ -8,5 +8,8 @@ export declare function defineConfig<KnownSocialProviders extends Record<string,
|
|
|
8
8
|
driver: K;
|
|
9
9
|
} & Parameters<AllyDriversList[K]>[0];
|
|
10
10
|
}[keyof AllyDriversList]>>(config: KnownSocialProviders): {
|
|
11
|
-
|
|
11
|
+
services: {
|
|
12
|
+
[K in keyof KnownSocialProviders]: (ctx: HttpContext) => ReturnType<AllyDriversList[KnownSocialProviders[K]['driver']]>;
|
|
13
|
+
};
|
|
14
|
+
driversInUse: Set<keyof AllyDriversList>;
|
|
12
15
|
};
|
|
@@ -12,15 +12,20 @@ import allyDriversCollection from './drivers_collection.js';
|
|
|
12
12
|
*/
|
|
13
13
|
export function defineConfig(config) {
|
|
14
14
|
/**
|
|
15
|
-
* Converting user defined config to an object of
|
|
15
|
+
* Converting user defined config to an object of services
|
|
16
16
|
* that can be injected into the AllyManager class
|
|
17
17
|
*/
|
|
18
|
-
const
|
|
18
|
+
const driversInUse = new Set();
|
|
19
|
+
const services = Object.keys(config).reduce((result, provider) => {
|
|
19
20
|
const providerConfig = config[provider];
|
|
21
|
+
driversInUse.add(providerConfig.driver);
|
|
20
22
|
result[provider] = (ctx) => {
|
|
21
23
|
return allyDriversCollection.create(providerConfig.driver, providerConfig, ctx);
|
|
22
24
|
};
|
|
23
25
|
return result;
|
|
24
26
|
}, {});
|
|
25
|
-
return
|
|
27
|
+
return {
|
|
28
|
+
services,
|
|
29
|
+
driversInUse,
|
|
30
|
+
};
|
|
26
31
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
2
|
import type { AllyDriversList } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A global collection of ally drivers.
|
|
5
|
+
*/
|
|
3
6
|
declare class AllyDriversCollection {
|
|
7
|
+
registerBundledDrivers(drivers: Set<keyof AllyDriversList>): Promise<void>;
|
|
4
8
|
/**
|
|
5
9
|
* List of registered drivers
|
|
6
10
|
*/
|
|
@@ -7,31 +7,52 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { RuntimeException } from '@poppinss/utils';
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { DiscordDriver } from './drivers/discord.js';
|
|
15
|
-
import { FacebookDriver } from './drivers/facebook.js';
|
|
16
|
-
import { LinkedInDriver } from './drivers/linked_in.js';
|
|
10
|
+
import debug from './debug.js';
|
|
11
|
+
/**
|
|
12
|
+
* A global collection of ally drivers.
|
|
13
|
+
*/
|
|
17
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
|
+
}
|
|
18
46
|
/**
|
|
19
47
|
* List of registered drivers
|
|
20
48
|
*/
|
|
21
|
-
list = {
|
|
22
|
-
discord: (config, ctx) => new DiscordDriver(ctx, config),
|
|
23
|
-
facebook: (config, ctx) => new FacebookDriver(ctx, config),
|
|
24
|
-
github: (config, ctx) => new GithubDriver(ctx, config),
|
|
25
|
-
google: (config, ctx) => new GoogleDriver(ctx, config),
|
|
26
|
-
linkedin: (config, ctx) => new LinkedInDriver(ctx, config),
|
|
27
|
-
spotify: (config, ctx) => new SpotifyDriver(ctx, config),
|
|
28
|
-
twitter: (config, ctx) => new TwitterDriver(ctx, config),
|
|
29
|
-
};
|
|
49
|
+
list = {};
|
|
30
50
|
/**
|
|
31
51
|
* Extend drivers collection and add a custom
|
|
32
52
|
* driver to it.
|
|
33
53
|
*/
|
|
34
54
|
extend(driverName, factoryCallback) {
|
|
55
|
+
debug('registering %s driver', driverName);
|
|
35
56
|
this.list[driverName] = factoryCallback;
|
|
36
57
|
return this;
|
|
37
58
|
}
|
|
@@ -43,6 +64,7 @@ class AllyDriversCollection {
|
|
|
43
64
|
if (!driverFactory) {
|
|
44
65
|
throw new RuntimeException(`Unknown ally driver "${String(name)}". Make sure the driver is registered`);
|
|
45
66
|
}
|
|
67
|
+
debug('creating instance of %s driver', name);
|
|
46
68
|
return driverFactory(config, ctx);
|
|
47
69
|
}
|
|
48
70
|
}
|
package/build/src/types.d.ts
CHANGED
|
@@ -380,4 +380,6 @@ export type AllyManagerDriverFactory = (ctx: HttpContext) => AllyDriverContract<
|
|
|
380
380
|
*/
|
|
381
381
|
export interface SocialProviders {
|
|
382
382
|
}
|
|
383
|
-
export type InferSocialProviders<T extends
|
|
383
|
+
export type InferSocialProviders<T extends {
|
|
384
|
+
services: Record<string, AllyManagerDriverFactory>;
|
|
385
|
+
}> = T['services'];
|
package/build/stubs/config.stub
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
---
|
|
2
2
|
to: {{ app.configPath('ally.ts') }}
|
|
3
3
|
---
|
|
4
|
-
import { defineConfig } from '@adonisjs/ally'
|
|
5
4
|
import env from '#start/env'
|
|
5
|
+
import { defineConfig } from '@adonisjs/ally'
|
|
6
|
+
|
|
7
|
+
const allyConfig = defineConfig({
|
|
8
|
+
{{#each providers as provider}}
|
|
9
|
+
{{provider.provider}}: {
|
|
10
|
+
driver: '{{provider.provider}}',
|
|
11
|
+
clientId: env.get('{{provider.envPrefix}}_CLIENT_ID'),
|
|
12
|
+
clientSecret: env.get('{{provider.envPrefix}}_CLIENT_SECRET'),
|
|
13
|
+
callbackUrl: '',
|
|
14
|
+
},
|
|
15
|
+
{{/each}}
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export default allyConfig
|
|
6
19
|
|
|
7
|
-
|
|
20
|
+
declare module '@adonisjs/ally/types' {
|
|
21
|
+
interface SocialProviders extends InferSocialProviders<typeof allyConfig> {}
|
|
22
|
+
}
|
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-2",
|
|
4
4
|
"description": "Social authentication provider for AdonisJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "build/index.js",
|
|
@@ -47,23 +47,23 @@
|
|
|
47
47
|
"author": "adonisjs,virk",
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@adonisjs/core": "^6.1.5-
|
|
50
|
+
"@adonisjs/core": "^6.1.5-15",
|
|
51
51
|
"@adonisjs/eslint-config": "^1.1.8",
|
|
52
52
|
"@adonisjs/prettier-config": "^1.1.8",
|
|
53
53
|
"@adonisjs/tsconfig": "^1.1.8",
|
|
54
|
-
"@commitlint/cli": "^17.6.
|
|
55
|
-
"@commitlint/config-conventional": "^17.6.
|
|
54
|
+
"@commitlint/cli": "^17.6.7",
|
|
55
|
+
"@commitlint/config-conventional": "^17.6.7",
|
|
56
56
|
"@japa/assert": "^2.0.0-1",
|
|
57
57
|
"@japa/expect-type": "^2.0.0-0",
|
|
58
58
|
"@japa/file-system": "^2.0.0-1",
|
|
59
59
|
"@japa/runner": "^3.0.0-6",
|
|
60
|
-
"@swc/core": "^1.3.
|
|
61
|
-
"@types/node": "^20.4.
|
|
62
|
-
"c8": "^8.0.
|
|
60
|
+
"@swc/core": "^1.3.74",
|
|
61
|
+
"@types/node": "^20.4.6",
|
|
62
|
+
"c8": "^8.0.1",
|
|
63
63
|
"copyfiles": "^2.4.1",
|
|
64
64
|
"del-cli": "^5.0.0",
|
|
65
65
|
"dotenv": "^16.3.1",
|
|
66
|
-
"eslint": "^8.
|
|
66
|
+
"eslint": "^8.46.0",
|
|
67
67
|
"github-label-sync": "^2.3.1",
|
|
68
68
|
"husky": "^8.0.3",
|
|
69
69
|
"nock": "^13.3.2",
|
|
@@ -76,6 +76,9 @@
|
|
|
76
76
|
"@poppinss/oauth-client": "^5.1.0-3",
|
|
77
77
|
"@poppinss/utils": "^6.5.0-3"
|
|
78
78
|
},
|
|
79
|
+
"peerDependencies": {
|
|
80
|
+
"@adonisjs/core": "^6.1.5-15"
|
|
81
|
+
},
|
|
79
82
|
"repository": {
|
|
80
83
|
"type": "git",
|
|
81
84
|
"url": "git+https://github.com/adonisjs/adonis-ally.git"
|
package/build/stubs/types.stub
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: {{ app.contractsPath('ally.ts') }}
|
|
3
|
-
---
|
|
4
|
-
import allyConfig from '#config/ally'
|
|
5
|
-
|
|
6
|
-
declare module '@adonisjs/ally/types' {
|
|
7
|
-
/**
|
|
8
|
-
* Here we get a list of social providers you have configured inside
|
|
9
|
-
* the config/ally.ts file.
|
|
10
|
-
*/
|
|
11
|
-
interface SocialProviders extends InferSocialProviders<typeof allyConfig> {}
|
|
12
|
-
}
|
|
File without changes
|
|
File without changes
|