@adonisjs/ally 5.0.0 → 5.0.1

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.js CHANGED
@@ -96,43 +96,43 @@ function defineConfig(config) {
96
96
  var services = {
97
97
  discord(config) {
98
98
  return configProvider.create(async () => {
99
- const { DiscordDriver } = await import("./discord-NGJGLGX7.js");
99
+ const { DiscordDriver } = await import("./src/drivers/discord.js");
100
100
  return (ctx) => new DiscordDriver(ctx, config);
101
101
  });
102
102
  },
103
103
  facebook(config) {
104
104
  return configProvider.create(async () => {
105
- const { FacebookDriver } = await import("./facebook-WTZGLDH5.js");
105
+ const { FacebookDriver } = await import("./src/drivers/facebook.js");
106
106
  return (ctx) => new FacebookDriver(ctx, config);
107
107
  });
108
108
  },
109
109
  github(config) {
110
110
  return configProvider.create(async () => {
111
- const { GithubDriver } = await import("./github-24BPMULZ.js");
111
+ const { GithubDriver } = await import("./src/drivers/github.js");
112
112
  return (ctx) => new GithubDriver(ctx, config);
113
113
  });
114
114
  },
115
115
  google(config) {
116
116
  return configProvider.create(async () => {
117
- const { GoogleDriver } = await import("./google-NMLTQESR.js");
117
+ const { GoogleDriver } = await import("./src/drivers/google.js");
118
118
  return (ctx) => new GoogleDriver(ctx, config);
119
119
  });
120
120
  },
121
121
  linkedin(config) {
122
122
  return configProvider.create(async () => {
123
- const { LinkedInDriver } = await import("./linked_in-HIRSEAEP.js");
123
+ const { LinkedInDriver } = await import("./src/drivers/linked_in.js");
124
124
  return (ctx) => new LinkedInDriver(ctx, config);
125
125
  });
126
126
  },
127
127
  spotify(config) {
128
128
  return configProvider.create(async () => {
129
- const { SpotifyDriver } = await import("./spotify-ESJDFUD6.js");
129
+ const { SpotifyDriver } = await import("./src/drivers/spotify.js");
130
130
  return (ctx) => new SpotifyDriver(ctx, config);
131
131
  });
132
132
  },
133
133
  twitter(config) {
134
134
  return configProvider.create(async () => {
135
- const { TwitterDriver } = await import("./twitter-QISDDK24.js");
135
+ const { TwitterDriver } = await import("./src/drivers/twitter.js");
136
136
  return (ctx) => new TwitterDriver(ctx, config);
137
137
  });
138
138
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../stubs/main.ts","../configure.ts","../src/define_config.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nexport { HttpClient as ApiRequest } from '@poppinss/oauth-client'\n\nexport * as errors from './src/errors.js'\nexport { configure } from './configure.js'\nexport { stubsRoot } from './stubs/main.js'\nexport { AllyManager } from './src/ally_manager.js'\nexport { defineConfig, services } from './src/define_config.js'\n\nexport { RedirectRequest } from './src/redirect_request.js'\nexport { Oauth1Driver } from './src/abstract_drivers/oauth1.js'\nexport { Oauth2Driver } from './src/abstract_drivers/oauth2.js'\n","/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { getDirname } from '@poppinss/utils'\n\nexport const stubsRoot = getDirname(import.meta.url)\n","/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type Configure from '@adonisjs/core/commands/configure'\nimport { stubsRoot } from './stubs/main.js'\n\n/**\n * List of available providers\n */\nconst AVAILABLE_PROVIDERS = [\n 'discord',\n 'facebook',\n 'github',\n 'google',\n 'linkedin',\n 'spotify',\n 'twitter',\n]\n\n/**\n * Configures the package\n */\nexport async function configure(command: Configure) {\n /**\n * Read providers from the CLI flags\n */\n let selectedProviders: string[] | string | undefined = command.parsedFlags.providers\n\n /**\n * Otherwise force prompt for selection\n */\n if (!selectedProviders) {\n selectedProviders = await command.prompt.multiple(\n 'Select the social auth providers you plan to use',\n AVAILABLE_PROVIDERS,\n {\n validate(value) {\n return !value || !value.length\n ? 'Select a social provider to configure the package'\n : true\n },\n }\n )\n }\n\n /**\n * Cast CLI string value to an array\n */\n let providers = (\n typeof selectedProviders === 'string' ? [selectedProviders] : selectedProviders\n ) as string[]\n\n /**\n * Validate CLI selection to contain known providers\n */\n const unknownProvider = providers.find((provider) => !AVAILABLE_PROVIDERS.includes(provider))\n if (unknownProvider) {\n command.exitCode = 1\n command.logger.error(`Invalid social provider \"${unknownProvider}\"`)\n return\n }\n\n const codemods = await command.createCodemods()\n\n /**\n * Publish config file\n */\n await codemods.makeUsingStub(stubsRoot, 'config/ally.stub', {\n providers: providers.map((provider) => {\n return { provider, envPrefix: provider.toUpperCase() }\n }),\n })\n\n /**\n * Publish provider\n */\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@adonisjs/ally/ally_provider')\n })\n\n /**\n * Define env variables for the selected providers\n */\n await codemods.defineEnvVariables(\n providers.reduce<Record<string, string>>((result, provider) => {\n result[`${provider.toUpperCase()}_CLIENT_ID`] = ''\n result[`${provider.toUpperCase()}_CLIENT_SECRET`] = ''\n return result\n }, {})\n )\n\n /**\n * Define env variables validation for the selected providers\n */\n await codemods.defineEnvValidations({\n variables: providers.reduce<Record<string, string>>((result, provider) => {\n result[`${provider.toUpperCase()}_CLIENT_ID`] = 'Env.schema.string()'\n result[`${provider.toUpperCase()}_CLIENT_SECRET`] = 'Env.schema.string()'\n return result\n }, {}),\n leadingComment: 'Variables for configuring ally package',\n })\n}\n","/*\n * @adonisjs/ally\n *\n * (c) Ally\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { configProvider } from '@adonisjs/core'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { ConfigProvider } from '@adonisjs/core/types'\n\nimport type { GoogleDriver } from './drivers/google.js'\nimport type { GithubDriver } from './drivers/github.js'\nimport type { SpotifyDriver } from './drivers/spotify.js'\nimport type { TwitterDriver } from './drivers/twitter.js'\nimport type { DiscordDriver } from './drivers/discord.js'\nimport type { FacebookDriver } from './drivers/facebook.js'\nimport type { LinkedInDriver } from './drivers/linked_in.js'\nimport type {\n GoogleDriverConfig,\n GithubDriverConfig,\n SpotifyDriverConfig,\n DiscordDriverConfig,\n TwitterDriverConfig,\n LinkedInDriverConfig,\n FacebookDriverConfig,\n AllyManagerDriverFactory,\n} from './types.js'\n\n/**\n * Shape of config after it has been resolved from\n * the config provider\n */\ntype ResolvedConfig<\n KnownSocialProviders extends Record<\n string,\n AllyManagerDriverFactory | ConfigProvider<AllyManagerDriverFactory>\n >,\n> = {\n [K in keyof KnownSocialProviders]: KnownSocialProviders[K] extends ConfigProvider<infer A>\n ? A\n : KnownSocialProviders[K]\n}\n\n/**\n * Define config for the ally\n */\nexport function defineConfig<\n KnownSocialProviders extends Record<\n string,\n AllyManagerDriverFactory | ConfigProvider<AllyManagerDriverFactory>\n >,\n>(config: KnownSocialProviders): ConfigProvider<ResolvedConfig<KnownSocialProviders>> {\n return configProvider.create(async (app) => {\n const serviceNames = Object.keys(config)\n const services = {} as Record<string, AllyManagerDriverFactory>\n\n for (let serviceName of serviceNames) {\n const service = config[serviceName]\n if (typeof service === 'function') {\n services[serviceName] = service\n } else {\n services[serviceName] = await service.resolver(app)\n }\n }\n\n return services as ResolvedConfig<KnownSocialProviders>\n })\n}\n\n/**\n * Helpers to configure social auth services\n */\nexport const services: {\n discord: (config: DiscordDriverConfig) => ConfigProvider<(ctx: HttpContext) => DiscordDriver>\n facebook: (config: FacebookDriverConfig) => ConfigProvider<(ctx: HttpContext) => FacebookDriver>\n github: (config: GithubDriverConfig) => ConfigProvider<(ctx: HttpContext) => GithubDriver>\n google: (config: GoogleDriverConfig) => ConfigProvider<(ctx: HttpContext) => GoogleDriver>\n linkedin: (config: LinkedInDriverConfig) => ConfigProvider<(ctx: HttpContext) => LinkedInDriver>\n spotify: (config: SpotifyDriverConfig) => ConfigProvider<(ctx: HttpContext) => SpotifyDriver>\n twitter: (config: TwitterDriverConfig) => ConfigProvider<(ctx: HttpContext) => TwitterDriver>\n} = {\n discord(config) {\n return configProvider.create(async () => {\n const { DiscordDriver } = await import('./drivers/discord.js')\n return (ctx) => new DiscordDriver(ctx, config)\n })\n },\n facebook(config) {\n return configProvider.create(async () => {\n const { FacebookDriver } = await import('./drivers/facebook.js')\n return (ctx) => new FacebookDriver(ctx, config)\n })\n },\n github(config) {\n return configProvider.create(async () => {\n const { GithubDriver } = await import('./drivers/github.js')\n return (ctx) => new GithubDriver(ctx, config)\n })\n },\n google(config) {\n return configProvider.create(async () => {\n const { GoogleDriver } = await import('./drivers/google.js')\n return (ctx) => new GoogleDriver(ctx, config)\n })\n },\n linkedin(config) {\n return configProvider.create(async () => {\n const { LinkedInDriver } = await import('./drivers/linked_in.js')\n return (ctx) => new LinkedInDriver(ctx, config)\n })\n },\n spotify(config) {\n return configProvider.create(async () => {\n const { SpotifyDriver } = await import('./drivers/spotify.js')\n return (ctx) => new SpotifyDriver(ctx, config)\n })\n },\n twitter(config) {\n return configProvider.create(async () => {\n const { TwitterDriver } = await import('./drivers/twitter.js')\n return (ctx) => new TwitterDriver(ctx, config)\n })\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;AASA,SAAuB,kBAAkB;;;ACAzC,SAAS,kBAAkB;AAEpB,IAAM,YAAY,WAAW,YAAY,GAAG;;;ACInD,IAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKA,eAAsB,UAAU,SAAoB;AAIlD,MAAI,oBAAmD,QAAQ,YAAY;AAK3E,MAAI,CAAC,mBAAmB;AACtB,wBAAoB,MAAM,QAAQ,OAAO;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,QACE,SAAS,OAAO;AACd,iBAAO,CAAC,SAAS,CAAC,MAAM,SACpB,sDACA;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAKA,MAAI,YACF,OAAO,sBAAsB,WAAW,CAAC,iBAAiB,IAAI;AAMhE,QAAM,kBAAkB,UAAU,KAAK,CAAC,aAAa,CAA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AACvC,YAAM,EAAE,cAAc,IAAI,MAAM,OAAO,uBAAsB;AAC7D,aAAO,CAAC,QAAQ,IAAI,cAAc,KAAK,MAAM;AAAA,IAC/C,CAAC;AAAA,EACH;AACF;","names":["services"]}
1
+ {"version":3,"sources":["../index.ts","../stubs/main.ts","../configure.ts","../src/define_config.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nexport { HttpClient as ApiRequest } from '@poppinss/oauth-client'\n\nexport * as errors from './src/errors.js'\nexport { configure } from './configure.js'\nexport { stubsRoot } from './stubs/main.js'\nexport { AllyManager } from './src/ally_manager.js'\nexport { defineConfig, services } from './src/define_config.js'\n\nexport { RedirectRequest } from './src/redirect_request.js'\nexport { Oauth1Driver } from './src/abstract_drivers/oauth1.js'\nexport { Oauth2Driver } from './src/abstract_drivers/oauth2.js'\n","/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { getDirname } from '@poppinss/utils'\n\nexport const stubsRoot = getDirname(import.meta.url)\n","/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type Configure from '@adonisjs/core/commands/configure'\nimport { stubsRoot } from './stubs/main.js'\n\n/**\n * List of available providers\n */\nconst AVAILABLE_PROVIDERS = [\n 'discord',\n 'facebook',\n 'github',\n 'google',\n 'linkedin',\n 'spotify',\n 'twitter',\n]\n\n/**\n * Configures the package\n */\nexport async function configure(command: Configure) {\n /**\n * Read providers from the CLI flags\n */\n let selectedProviders: string[] | string | undefined = command.parsedFlags.providers\n\n /**\n * Otherwise force prompt for selection\n */\n if (!selectedProviders) {\n selectedProviders = await command.prompt.multiple(\n 'Select the social auth providers you plan to use',\n AVAILABLE_PROVIDERS,\n {\n validate(value) {\n return !value || !value.length\n ? 'Select a social provider to configure the package'\n : true\n },\n }\n )\n }\n\n /**\n * Cast CLI string value to an array\n */\n let providers = (\n typeof selectedProviders === 'string' ? [selectedProviders] : selectedProviders\n ) as string[]\n\n /**\n * Validate CLI selection to contain known providers\n */\n const unknownProvider = providers.find((provider) => !AVAILABLE_PROVIDERS.includes(provider))\n if (unknownProvider) {\n command.exitCode = 1\n command.logger.error(`Invalid social provider \"${unknownProvider}\"`)\n return\n }\n\n const codemods = await command.createCodemods()\n\n /**\n * Publish config file\n */\n await codemods.makeUsingStub(stubsRoot, 'config/ally.stub', {\n providers: providers.map((provider) => {\n return { provider, envPrefix: provider.toUpperCase() }\n }),\n })\n\n /**\n * Publish provider\n */\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@adonisjs/ally/ally_provider')\n })\n\n /**\n * Define env variables for the selected providers\n */\n await codemods.defineEnvVariables(\n providers.reduce<Record<string, string>>((result, provider) => {\n result[`${provider.toUpperCase()}_CLIENT_ID`] = ''\n result[`${provider.toUpperCase()}_CLIENT_SECRET`] = ''\n return result\n }, {})\n )\n\n /**\n * Define env variables validation for the selected providers\n */\n await codemods.defineEnvValidations({\n variables: providers.reduce<Record<string, string>>((result, provider) => {\n result[`${provider.toUpperCase()}_CLIENT_ID`] = 'Env.schema.string()'\n result[`${provider.toUpperCase()}_CLIENT_SECRET`] = 'Env.schema.string()'\n return result\n }, {}),\n leadingComment: 'Variables for configuring ally package',\n })\n}\n","/*\n * @adonisjs/ally\n *\n * (c) Ally\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { configProvider } from '@adonisjs/core'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { ConfigProvider } from '@adonisjs/core/types'\n\nimport type { GoogleDriver } from './drivers/google.js'\nimport type { GithubDriver } from './drivers/github.js'\nimport type { SpotifyDriver } from './drivers/spotify.js'\nimport type { TwitterDriver } from './drivers/twitter.js'\nimport type { DiscordDriver } from './drivers/discord.js'\nimport type { FacebookDriver } from './drivers/facebook.js'\nimport type { LinkedInDriver } from './drivers/linked_in.js'\nimport type {\n GoogleDriverConfig,\n GithubDriverConfig,\n SpotifyDriverConfig,\n DiscordDriverConfig,\n TwitterDriverConfig,\n LinkedInDriverConfig,\n FacebookDriverConfig,\n AllyManagerDriverFactory,\n} from './types.js'\n\n/**\n * Shape of config after it has been resolved from\n * the config provider\n */\ntype ResolvedConfig<\n KnownSocialProviders extends Record<\n string,\n AllyManagerDriverFactory | ConfigProvider<AllyManagerDriverFactory>\n >,\n> = {\n [K in keyof KnownSocialProviders]: KnownSocialProviders[K] extends ConfigProvider<infer A>\n ? A\n : KnownSocialProviders[K]\n}\n\n/**\n * Define config for the ally\n */\nexport function defineConfig<\n KnownSocialProviders extends Record<\n string,\n AllyManagerDriverFactory | ConfigProvider<AllyManagerDriverFactory>\n >,\n>(config: KnownSocialProviders): ConfigProvider<ResolvedConfig<KnownSocialProviders>> {\n return configProvider.create(async (app) => {\n const serviceNames = Object.keys(config)\n const services = {} as Record<string, AllyManagerDriverFactory>\n\n for (let serviceName of serviceNames) {\n const service = config[serviceName]\n if (typeof service === 'function') {\n services[serviceName] = service\n } else {\n services[serviceName] = await service.resolver(app)\n }\n }\n\n return services as ResolvedConfig<KnownSocialProviders>\n })\n}\n\n/**\n * Helpers to configure social auth services\n */\nexport const services: {\n discord: (config: DiscordDriverConfig) => ConfigProvider<(ctx: HttpContext) => DiscordDriver>\n facebook: (config: FacebookDriverConfig) => ConfigProvider<(ctx: HttpContext) => FacebookDriver>\n github: (config: GithubDriverConfig) => ConfigProvider<(ctx: HttpContext) => GithubDriver>\n google: (config: GoogleDriverConfig) => ConfigProvider<(ctx: HttpContext) => GoogleDriver>\n linkedin: (config: LinkedInDriverConfig) => ConfigProvider<(ctx: HttpContext) => LinkedInDriver>\n spotify: (config: SpotifyDriverConfig) => ConfigProvider<(ctx: HttpContext) => SpotifyDriver>\n twitter: (config: TwitterDriverConfig) => ConfigProvider<(ctx: HttpContext) => TwitterDriver>\n} = {\n discord(config) {\n return configProvider.create(async () => {\n const { DiscordDriver } = await import('./drivers/discord.js')\n return (ctx) => new DiscordDriver(ctx, config)\n })\n },\n facebook(config) {\n return configProvider.create(async () => {\n const { FacebookDriver } = await import('./drivers/facebook.js')\n return (ctx) => new FacebookDriver(ctx, config)\n })\n },\n github(config) {\n return configProvider.create(async () => {\n const { GithubDriver } = await import('./drivers/github.js')\n return (ctx) => new GithubDriver(ctx, config)\n })\n },\n google(config) {\n return configProvider.create(async () => {\n const { GoogleDriver } = await import('./drivers/google.js')\n return (ctx) => new GoogleDriver(ctx, config)\n })\n },\n linkedin(config) {\n return configProvider.create(async () => {\n const { LinkedInDriver } = await import('./drivers/linked_in.js')\n return (ctx) => new LinkedInDriver(ctx, config)\n })\n },\n spotify(config) {\n return configProvider.create(async () => {\n const { SpotifyDriver } = await import('./drivers/spotify.js')\n return (ctx) => new SpotifyDriver(ctx, config)\n })\n },\n twitter(config) {\n return configProvider.create(async () => {\n const { TwitterDriver } = await import('./drivers/twitter.js')\n return (ctx) => new TwitterDriver(ctx, config)\n })\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;AASA,SAAuB,kBAAkB;;;ACAzC,SAAS,kBAAkB;AAEpB,IAAM,YAAY,WAAW,YAAY,GAAG;;;ACInD,IAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKA,eAAsB,UAAU,SAAoB;AAIlD,MAAI,oBAAmD,QAAQ,YAAY;AAK3E,MAAI,CAAC,mBAAmB;AACtB,wBAAoB,MAAM,QAAQ,OAAO;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,QACE,SAAS,OAAO;AACd,iBAAO,CAAC,SAAS,CAAC,MAAM,SACpB,sDACA;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAKA,MAAI,YACF,OAAO,sBAAsB,WAAW,CAAC,iBAAiB,IAAI;AAMhE,QAA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,QAAQ;AACd,WAAO,eAAe,OAAO,YAAY;AACvC,YAAM,EAAE,cAAc,IAAI,MAAM,OAAO,0BAAsB;AAC7D,aAAO,CAAC,QAAQ,IAAI,cAAc,KAAK,MAAM;AAAA,IAC/C,CAAC;AAAA,EACH;AACF;","names":["services"]}
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Oauth2Driver
3
- } from "./chunk-OSVNBZ7V.js";
4
- import "./chunk-UF7PETXM.js";
5
- import "./chunk-CSAU5B4Q.js";
3
+ } from "../../chunk-OSVNBZ7V.js";
4
+ import "../../chunk-UF7PETXM.js";
5
+ import "../../chunk-CSAU5B4Q.js";
6
6
 
7
7
  // src/drivers/discord.ts
8
8
  var DiscordDriver = class extends Oauth2Driver {
@@ -133,4 +133,4 @@ var DiscordDriver = class extends Oauth2Driver {
133
133
  export {
134
134
  DiscordDriver
135
135
  };
136
- //# sourceMappingURL=discord-NGJGLGX7.js.map
136
+ //# sourceMappingURL=discord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/drivers/discord.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { HttpClient } from '@poppinss/oauth-client'\n\nimport type {\n DiscordScopes,\n DiscordToken,\n ApiRequestContract,\n DiscordDriverConfig,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\n/**\n * Discord driver to login user via Discord\n */\nexport class DiscordDriver extends Oauth2Driver<DiscordToken, DiscordScopes> {\n protected accessTokenUrl = 'https://discord.com/api/oauth2/token'\n protected authorizeUrl = 'https://discord.com/api/oauth2/authorize'\n protected userInfoUrl = 'https://discord.com/api/users/@me'\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"discord_oauth_state\"\n */\n protected stateCookieName = 'discord_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from Discord\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: DiscordDriverConfig\n ) {\n super(ctx, config)\n\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<DiscordScopes>) {\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['identify', 'email'])\n\n request.param('response_type', 'code')\n request.param('grant_type', 'authorization_code')\n\n /**\n * Define params based upon user config\n */\n if (this.config.prompt) {\n request.param('prompt', this.config.prompt)\n }\n if (this.config.guildId) {\n request.param('guild_id', this.config.guildId)\n }\n if (this.config.disableGuildSelect !== undefined) {\n request.param('disable_guild_select', this.config.disableGuildSelect)\n }\n if (this.config.permissions !== undefined) {\n request.param('permissions', this.config.permissions)\n }\n }\n\n /**\n * Configuring the access token API request to send extra fields\n */\n protected configureAccessTokenRequest(request: ApiRequestContract) {\n /**\n * Send state to Discord when request is not stateles\n */\n if (!this.isStateless) {\n request.field('state', this.stateCookieValue)\n }\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `Bearer ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the Discord API\n * https://discord.com/developers/docs/resources/user#get-current-user\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token)\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n return {\n id: body.id,\n name: `${body.username}#${body.discriminator}`,\n nickName: body.username,\n avatarUrl: body.avatar\n ? `https://cdn.discordapp.com/avatars/${body.id}/${body.avatar}.${\n body.avatar.startsWith('a_') ? 'gif' : 'png'\n }`\n : `https://cdn.discordapp.com/embed/avatars/${body.discriminator % 5}.png`,\n email: body.email, // May not always be there (requires email scope)\n emailVerificationState:\n 'verified' in body\n ? body.verified\n ? ('verified' as const)\n : ('unverified' as const)\n : ('unsupported' as const),\n original: body,\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'access_denied'\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n\n return {\n ...user,\n token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n\n return {\n ...user,\n token: { token, type: 'bearer' as const },\n }\n }\n}\n"],"mappings":";;;;;;;AAwBO,IAAM,gBAAN,cAA4B,aAA0C;AAAA,EAoC3E,YACE,KACO,QACP;AACA,UAAM,KAAK,MAAM;AAFV;AAQP,SAAK,UAAU;AAAA,EACjB;AAAA,EA9CU,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,cAAc;AAAA;AAAA;AAAA;AAAA,EAKd,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAkBlB,yBAAyB,SAAiD;AAIlF,YAAQ,OAAO,KAAK,OAAO,UAAU,CAAC,YAAY,OAAO,CAAC;AAE1D,YAAQ,MAAM,iBAAiB,MAAM;A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ACA,4CAA4C,KAAK,gBAAgB,CAAC;AAAA,MACtE,OAAO,KAAK;AAAA;AAAA,MACZ,wBACE,cAAc,OACV,KAAK,WACF,aACA,eACF;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,eAAwB;AACtB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAEA,WAAO,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,UAAkD;AAC3D,UAAM,QAAQ,MAAM,KAAK,YAAY,QAAQ;AAC7C,UAAM,OAAO,MAAM,KAAK,YAAY,MAAM,OAAO,QAAQ;AAEzD,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,OAAe,UAAkD;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AAEnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Oauth2Driver
3
- } from "./chunk-OSVNBZ7V.js";
4
- import "./chunk-UF7PETXM.js";
5
- import "./chunk-CSAU5B4Q.js";
3
+ } from "../../chunk-OSVNBZ7V.js";
4
+ import "../../chunk-UF7PETXM.js";
5
+ import "../../chunk-CSAU5B4Q.js";
6
6
 
7
7
  // src/drivers/facebook.ts
8
8
  var FacebookDriver = class extends Oauth2Driver {
@@ -134,4 +134,4 @@ var FacebookDriver = class extends Oauth2Driver {
134
134
  export {
135
135
  FacebookDriver
136
136
  };
137
- //# sourceMappingURL=facebook-WTZGLDH5.js.map
137
+ //# sourceMappingURL=facebook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/drivers/facebook.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpClient } from '@poppinss/oauth-client'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type {\n FacebookToken,\n FacebookScopes,\n LiteralStringUnion,\n ApiRequestContract,\n FacebookDriverConfig,\n FacebookProfileFields,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\n/**\n * Facebook driver to login user via Facebook\n */\nexport class FacebookDriver extends Oauth2Driver<FacebookToken, FacebookScopes> {\n protected accessTokenUrl = 'https://graph.facebook.com/v10.0/oauth/access_token'\n protected authorizeUrl = 'https://www.facebook.com/v10.0/dialog/oauth'\n protected userInfoUrl = 'https://graph.facebook.com/v10.0/me'\n\n /**\n * The default set of fields to query for the user request\n */\n protected userFields: LiteralStringUnion<FacebookProfileFields>[] = [\n 'name',\n 'first_name',\n 'last_name',\n 'link',\n 'email',\n 'picture.width(400).height(400)',\n 'verified',\n ]\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"facebok_oauth_state\"\n */\n protected stateCookieName = 'facebok_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from Facebok\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: FacebookDriverConfig\n ) {\n super(ctx, config)\n\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<FacebookScopes>) {\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['email'])\n\n request.param('response_type', 'code')\n request.param('grant_type', 'authorization_code')\n\n /**\n * Define params based upon user config\n */\n if (this.config.display) {\n request.param('display', this.config.display)\n }\n if (this.config.authType) {\n request.param('auth_type', this.config.authType)\n }\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `Bearer ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the Facebook API\n * https://developers.facebook.com/docs/graph-api/reference/user/\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token)\n request.param('fields', (this.config.userFields || this.userFields).join(','))\n\n const body = await request.get()\n\n /**\n * Invoke callback if defined\n */\n if (typeof callback === 'function') {\n callback(request)\n }\n\n return {\n id: body.id,\n name: body.name,\n nickName: body.name,\n // https://developers.facebook.com/docs/graph-api/reference/user/picture/\n avatarUrl: body.picture?.data?.url || null,\n email: body.email || null, // May not always be there (requires email scope)\n // Important note: https://developers.facebook.com/docs/facebook-login/multiple-providers#postfb1\n emailVerificationState:\n 'verified' in body\n ? body.verified\n ? ('verified' as const)\n : ('unverified' as const)\n : ('unsupported' as const),\n original: body,\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'access_denied'\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n\n return {\n ...user,\n token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n\n return {\n ...user,\n token: { token, type: 'bearer' as const },\n }\n }\n}\n"],"mappings":";;;;;;;AAyBO,IAAM,iBAAN,cAA6B,aAA4C;AAAA,EAiD9E,YACE,KACO,QACP;AACA,UAAM,KAAK,MAA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GAAG,CAAC;AAE7E,UAAM,OAAO,MAAM,QAAQ,IAAI;AAK/B,QAAI,OAAO,aAAa,YAAY;AAClC,eAAS,OAAO;AAAA,IAClB;AAEA,WAAO;AAAA,MACL,IAAI,KAAK;AAAA,MACT,MAAM,KAAK;AAAA,MACX,UAAU,KAAK;AAAA;AAAA,MAEf,WAAW,KAAK,SAAS,MAAM,OAAO;AAAA,MACtC,OAAO,KAAK,SAAS;AAAA;AAAA;AAAA,MAErB,wBACE,cAAc,OACV,KAAK,WACF,aACA,eACF;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,eAAwB;AACtB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAEA,WAAO,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,UAAkD;AAC3D,UAAM,QAAQ,MAAM,KAAK,YAAY,QAAQ;AAC7C,UAAM,OAAO,MAAM,KAAK,YAAY,MAAM,OAAO,QAAQ;AAEzD,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,OAAe,UAAkD;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AAEnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Oauth2Driver
3
- } from "./chunk-OSVNBZ7V.js";
4
- import "./chunk-UF7PETXM.js";
5
- import "./chunk-CSAU5B4Q.js";
3
+ } from "../../chunk-OSVNBZ7V.js";
4
+ import "../../chunk-UF7PETXM.js";
5
+ import "../../chunk-CSAU5B4Q.js";
6
6
 
7
7
  // src/drivers/github.ts
8
8
  var GithubDriver = class extends Oauth2Driver {
@@ -170,4 +170,4 @@ var GithubDriver = class extends Oauth2Driver {
170
170
  export {
171
171
  GithubDriver
172
172
  };
173
- //# sourceMappingURL=github-24BPMULZ.js.map
173
+ //# sourceMappingURL=github.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/drivers/github.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { HttpClient } from '@poppinss/oauth-client'\nimport type {\n GithubToken,\n GithubScopes,\n AllyUserContract,\n GithubDriverConfig,\n ApiRequestContract,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\n/**\n * Github driver to login user via Github\n */\nexport class GithubDriver extends Oauth2Driver<GithubToken, GithubScopes> {\n protected accessTokenUrl = 'https://github.com/login/oauth/access_token'\n protected authorizeUrl = 'https://github.com/login/oauth/authorize'\n protected userInfoUrl = 'https://api.github.com/user'\n protected userEmailUrl = 'https://api.github.com/user/emails'\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"gh_oauth_state\"\n */\n protected stateCookieName = 'gh_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from Github\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: GithubDriverConfig\n ) {\n super(ctx, config)\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<GithubScopes>) {\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['user'])\n\n /**\n * Set \"allow_signup\" option when defined\n */\n if (this.config.allowSignup !== undefined) {\n request.param('allow_signup', this.config.allowSignup)\n }\n\n /**\n * Set \"login\" option when defined\n */\n if (this.config.login) {\n request.param('login', this.config.login)\n }\n }\n\n /**\n * Configuring the access token API request to send extra fields\n */\n protected configureAccessTokenRequest(request: ApiRequestContract) {\n /**\n * Send state to github when request is not stateles\n */\n if (!this.isStateless) {\n request.field('state', this.stateCookieValue)\n }\n\n /**\n * Clearing the default defined \"grant_type\". Github doesn't accept this.\n * https://github.com/poppinss/oauth-client#following-is-the-list-of-fieldsparams-set-by-the-clients-implicitly\n */\n request.clearField('grant_type')\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `token ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the Github API\n * https://docs.github.com/en/rest/reference/users#get-the-authenticated-user\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token)\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n return {\n id: body.id,\n nickName: body.name,\n email: body.email, // May not always be there\n emailVerificationState: (body.email\n ? 'verified'\n : 'unsupported') as AllyUserContract<any>['emailVerificationState'],\n name: body.name,\n avatarUrl: body.avatar_url,\n original: body,\n }\n }\n\n /**\n * Fetches the user email from the Github API.\n * https://docs.github.com/en/rest/reference/users#list-email-addresses-for-the-authenticated-user\n */\n protected async getUserEmail(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(\n this.config.userEmailUrl || this.userEmailUrl,\n token\n )\n\n if (typeof callback === 'function') {\n callback(request)\n }\n\n try {\n let emails = await request.get()\n\n /**\n * Sort emails to keep the primary ones on the top\n */\n emails = emails.sort((email: any) => (email.primary ? -1 : 1))\n\n /**\n * Get the first verified email of the user\n */\n let mainEmail = emails.find((email: any) => email.verified)\n\n /**\n * If there are no verified emails, then get any first one\n */\n if (!mainEmail) {\n mainEmail = emails[0]\n }\n\n return mainEmail\n } catch (error) {\n if (error && error.response && error.response.statusCode === 404) {\n return\n }\n throw error\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'access_denied'\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n\n /**\n * Fetch email separately\n */\n if (!user.email) {\n this.ctx.logger.trace('Fetching github user email separately')\n\n const emailResponse = await this.getUserEmail(token.token, callback)\n if (emailResponse) {\n user.email = emailResponse.email\n user.emailVerificationState = emailResponse.verified\n ? ('verified' as const)\n : ('unverified' as const)\n }\n }\n\n return {\n ...user,\n token: token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n\n /**\n * Fetch email separately\n */\n if (!user.email) {\n this.ctx.logger.trace('Fetching github user email separately')\n\n const emailResponse = await this.getUserEmail(token, callback)\n if (emailResponse) {\n user.email = emailResponse.email\n user.emailVerificationState = emailResponse.verified\n ? ('verified' as const)\n : ('unverified' as const)\n }\n }\n\n return {\n ...user,\n token: { token, type: 'bearer' as const },\n }\n }\n}\n"],"mappings":";;;;;;;AAwBO,IAAM,eAAN,cAA2B,aAAwC;AAAA,EAqCxE,YACE,KACO,QACP;AACA,UAAM,KAAK,MAAM;AAFV;AAOP,SAAK,UAAU;AAAA,EACjB;AAAA,EA9CU,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,eAAe;AAAA;AAAA;AAAA;AAAA,EAKf,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAA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;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AAKnD,QAAI,CAAC,KAAK,OAAO;AACf,WAAK,IAAI,OAAO,MAAM,uCAAuC;AAE7D,YAAM,gBAAgB,MAAM,KAAK,aAAa,OAAO,QAAQ;AAC7D,UAAI,eAAe;AACjB,aAAK,QAAQ,cAAc;AAC3B,aAAK,yBAAyB,cAAc,WACvC,aACA;AAAA,MACP;AAAA,IACF;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Oauth2Driver
3
- } from "./chunk-OSVNBZ7V.js";
4
- import "./chunk-UF7PETXM.js";
5
- import "./chunk-CSAU5B4Q.js";
3
+ } from "../../chunk-OSVNBZ7V.js";
4
+ import "../../chunk-UF7PETXM.js";
5
+ import "../../chunk-CSAU5B4Q.js";
6
6
 
7
7
  // src/drivers/google.ts
8
8
  var SCOPE_PREFIXES = {
@@ -181,4 +181,4 @@ var GoogleDriver = class extends Oauth2Driver {
181
181
  export {
182
182
  GoogleDriver
183
183
  };
184
- //# sourceMappingURL=google-NMLTQESR.js.map
184
+ //# sourceMappingURL=google.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/drivers/google.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { HttpClient } from '@poppinss/oauth-client'\nimport type {\n GoogleToken,\n GoogleScopes,\n GoogleDriverConfig,\n ApiRequestContract,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\nconst SCOPE_PREFIXES = {\n 'https://www.googleapis.com/auth': [\n 'userinfo.email',\n 'userinfo.profile',\n 'contacts',\n 'contacts.other.readonly',\n 'contacts.readonly',\n 'directory.readonly',\n 'user.addresses.read',\n 'user.birthday.read',\n 'user.emails.read',\n 'user.gender.read',\n 'user.organization.read',\n 'user.phonenumbers.read',\n 'analytics',\n 'analytics.readonly',\n 'documents',\n 'documents.readonly',\n 'forms',\n 'forms.currentonly',\n 'groups',\n 'spreadsheets',\n 'calendar',\n 'calendar.events',\n 'calendar.events.readonly',\n 'calendar.readonly',\n 'calendar.settings.readonly',\n 'drive',\n 'drive.appdata',\n 'drive.file',\n 'drive.metadata',\n 'drive.metadata.readonly',\n 'drive.photos.readonly',\n 'drive.readonly',\n 'drive.scripts',\n ],\n}\n\n/**\n * Google driver to login user via Google\n */\nexport class GoogleDriver extends Oauth2Driver<GoogleToken, GoogleScopes> {\n protected accessTokenUrl = 'https://oauth2.googleapis.com/token'\n protected authorizeUrl = 'https://accounts.google.com/o/oauth2/v2/auth'\n protected userInfoUrl = 'https://www.googleapis.com/oauth2/v3/userinfo'\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"google_oauth_state\"\n */\n protected stateCookieName = 'google_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from google\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: GoogleDriverConfig\n ) {\n super(ctx, config)\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<GoogleScopes>) {\n request.transformScopes((scopes) => this.buildScopes(scopes))\n\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['openid', 'userinfo.email', 'userinfo.profile'])\n\n /**\n * Set \"response_type\" param\n */\n request.param('response_type', 'code')\n\n /**\n * Define params based upon user config\n */\n if (this.config.accessType) {\n request.param('access_type', this.config.accessType)\n }\n if (this.config.prompt) {\n request.param('prompt', this.config.prompt)\n }\n if (this.config.display) {\n request.param('display', this.config.display)\n }\n if (this.config.hostedDomain) {\n request.param('hd', this.config.hostedDomain)\n }\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `Bearer ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the Google API\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token)\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n\n return {\n id: body.sub,\n nickName: body.name,\n name: body.name,\n email: body.email,\n avatarUrl: body.picture,\n emailVerificationState: body.email_verified ? ('verified' as const) : ('unverified' as const),\n original: body,\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'access_denied'\n }\n\n /**\n * Get access token\n */\n async accessToken(callback?: (request: ApiRequestContract) => void): Promise<GoogleToken> {\n const token = await super.accessToken(callback)\n\n return {\n ...token,\n idToken: token.id_token,\n }\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n\n return {\n ...user,\n token: token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n\n return {\n ...user,\n token: { token, type: 'bearer' as const },\n }\n }\n\n /**\n * Prefixes google scopes with the url\n */\n buildScopes(scopes: string[]) {\n return scopes.map((name) => {\n const prefix = Object.keys(SCOPE_PREFIXES).find((one) =>\n SCOPE_PREFIXES[one as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;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,UAAkD;AAC3D,UAAM,QAAQ,MAAM,KAAK,YAAY,QAAQ;AAC7C,UAAM,OAAO,MAAM,KAAK,YAAY,MAAM,OAAO,QAAQ;AAEzD,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,OAAe,UAAkD;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AAEnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,QAAkB;AAC5B,WAAO,OAAO,IAAI,CAAC,SAAS;AAC1B,YAAM,SAAS,OAAO,KAAK,cAAc,EAAE;AAAA,QAAK,CAAC,QAC/C,eAAe,GAAkC,EAAE,SAAS,IAAI;AAAA,MAClE;AACA,aAAO,SAAS,GAAG,MAAM,IAAI,IAAI,KAAK;AAAA,IACxC,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Oauth2Driver
3
- } from "./chunk-OSVNBZ7V.js";
4
- import "./chunk-UF7PETXM.js";
5
- import "./chunk-CSAU5B4Q.js";
3
+ } from "../../chunk-OSVNBZ7V.js";
4
+ import "../../chunk-UF7PETXM.js";
5
+ import "../../chunk-CSAU5B4Q.js";
6
6
 
7
7
  // src/drivers/linked_in.ts
8
8
  import { Exception } from "@poppinss/utils";
@@ -150,4 +150,4 @@ var LinkedInDriver = class extends Oauth2Driver {
150
150
  export {
151
151
  LinkedInDriver
152
152
  };
153
- //# sourceMappingURL=linked_in-HIRSEAEP.js.map
153
+ //# sourceMappingURL=linked_in.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/drivers/linked_in.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { Exception } from '@poppinss/utils'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { HttpClient } from '@poppinss/oauth-client'\nimport type {\n LinkedInToken,\n LinkedInScopes,\n ApiRequestContract,\n LinkedInDriverConfig,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\n/**\n * LinkedIn driver to login user via LinkedIn\n */\nexport class LinkedInDriver extends Oauth2Driver<LinkedInToken, LinkedInScopes> {\n protected accessTokenUrl = 'https://www.linkedin.com/oauth/v2/accessToken'\n protected authorizeUrl = 'https://www.linkedin.com/oauth/v2/authorization'\n protected userInfoUrl = 'https://api.linkedin.com/v2/me'\n protected userEmailUrl = 'https://api.linkedin.com/v2/clientAwareMemberHandles'\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"linkedin_oauth_state\"\n */\n protected stateCookieName = 'linkedin_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from linkedin\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: LinkedInDriverConfig\n ) {\n super(ctx, config)\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<LinkedInScopes>) {\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['r_emailaddress', 'r_liteprofile'])\n\n /**\n * Set \"response_type\" param\n */\n request.param('response_type', 'code')\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `Bearer ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the LinkedIn API\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n let url = this.config.userInfoUrl || this.userInfoUrl\n const request = this.getAuthenticatedRequest(url, token)\n request.param(\n 'projection',\n '(id,localizedLastName,localizedFirstName,vanityName,profilePicture(displayImage~digitalmediaAsset:playableStreams))'\n )\n\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n\n /**\n * Finding the user avatar\n */\n let avatar: string = ''\n if (body.profilePicture) {\n const avatars = body.profilePicture['displayImage~']['elements'] || []\n if (avatars.length && avatars[0].identifiers && avatars[0].identifiers.length) {\n avatar = avatars[0].identifiers[0].identifier\n }\n }\n\n return {\n id: body.id,\n nickName: body.vanityName || `${body.localizedFirstName} ${body.localizedLastName}`,\n name: `${body.localizedFirstName} ${body.localizedLastName}`,\n avatarUrl: avatar,\n original: body,\n }\n }\n\n /**\n * Fetches the user email from the LinkedIn API\n */\n protected async getUserEmail(token: string, callback?: (request: ApiRequestContract) => void) {\n let url = this.config.userEmailUrl || this.userEmailUrl\n const request = this.getAuthenticatedRequest(url, token)\n request.param('q', 'members')\n request.param('projection', '(elements*(primary,type,handle~))')\n\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n let mainEmail = body.elements.find((resource: any) => {\n return resource.type === 'EMAIL' && resource['handle~']\n })\n\n /**\n * We except email to always exist\n */\n if (!mainEmail) {\n throw new Exception(\n 'Cannot request user email. Make sure you are using the \"r_emailaddress\" scope'\n )\n }\n\n return mainEmail['handle~']['emailAddress']\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'user_cancelled_login' || error === 'user_cancelled_authorize'\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n const email = await this.getUserEmail(token.token, callback)\n\n return {\n ...user,\n email: email,\n emailVerificationState: 'unsupported' as const,\n token: token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n const email = await this.getUserEmail(token, callback)\n\n return {\n ...user,\n email: email,\n emailVerificationState: 'unsupported' as const,\n token: { token, type: 'bearer' as const },\n }\n }\n}\n"],"mappings":";;;;;;;AASA,SAAS,iBAAiB;AAenB,IAAM,iBAAN,cAA6B,aAA4C;AAAA,EAqC9E,YACE,KACO,QACP;AACA,UAAM,KAAK,MAAM;AAFV;AAOP,SAAK,UAAU;AAAA,EACjB;AAAA,EA9CU,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,eAAe;AAAA;AAAA;AAAA;AAAA,EAKf,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAiBlB,yBAAyB,SAAkD;AAInF,YAAQ,OAAO,KAAK,OAAO,UAAU,CAAC,kBAAkB,eAAe,CAAC;AAKxE,YAAQ,MAAM,iBAAiB,MAAM;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,EAKU,wBAAwB,KAAa,OAA2B;AACxE,UAAM,UAAU,KAAK,WAAW,GAAG;AACnC,YAAQ,OAAO,iBAAiB,UAAU,KAAK,EAAE;AACjD,YAAQ,OAAO,UAAU,kBAAkB;AAC3C,YAAQ,QAAQ,MAAM;AACtB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAgB,YAAY,OAAe,UAAkD;AAC3F,QAAI,MAAM,KAAK,OAAO,eA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AAAA;AAAA;AAAA;AAAA,EAKA,eAAwB;AACtB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAEA,WAAO,UAAU,0BAA0B,UAAU;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,UAAkD;AAC3D,UAAM,QAAQ,MAAM,KAAK,YAAY,QAAQ;AAC7C,UAAM,OAAO,MAAM,KAAK,YAAY,MAAM,OAAO,QAAQ;AACzD,UAAM,QAAQ,MAAM,KAAK,aAAa,MAAM,OAAO,QAAQ;AAE3D,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,MACA,wBAAwB;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,OAAe,UAAkD;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AACnD,UAAM,QAAQ,MAAM,KAAK,aAAa,OAAO,QAAQ;AAErD,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,MACA,wBAAwB;AAAA,MACxB,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Oauth2Driver
3
- } from "./chunk-OSVNBZ7V.js";
4
- import "./chunk-UF7PETXM.js";
5
- import "./chunk-CSAU5B4Q.js";
3
+ } from "../../chunk-OSVNBZ7V.js";
4
+ import "../../chunk-UF7PETXM.js";
5
+ import "../../chunk-CSAU5B4Q.js";
6
6
 
7
7
  // src/drivers/spotify.ts
8
8
  var SpotifyDriver = class extends Oauth2Driver {
@@ -115,4 +115,4 @@ var SpotifyDriver = class extends Oauth2Driver {
115
115
  export {
116
116
  SpotifyDriver
117
117
  };
118
- //# sourceMappingURL=spotify-ESJDFUD6.js.map
118
+ //# sourceMappingURL=spotify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/drivers/spotify.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { HttpClient } from '@poppinss/oauth-client'\nimport type {\n SpotifyScopes,\n SpotifyToken,\n ApiRequestContract,\n SpotifyDriverConfig,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\n/**\n * Spotify driver to login user via Spotify\n */\nexport class SpotifyDriver extends Oauth2Driver<SpotifyToken, SpotifyScopes> {\n protected accessTokenUrl = 'https://accounts.spotify.com/api/token'\n protected authorizeUrl = 'https://accounts.spotify.com/authorize'\n protected userInfoUrl = 'https://api.spotify.com/v1/me'\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"spotify_oauth_state\"\n */\n protected stateCookieName = 'spotify_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from Spotify\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: SpotifyDriverConfig\n ) {\n super(ctx, config)\n\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<SpotifyScopes>) {\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['user-read-email'])\n\n request.param('response_type', 'code')\n request.param('grant_type', 'authorization_code')\n\n /**\n * Define params based upon user config\n */\n if (this.config.showDialog) {\n request.param('show_dialog', this.config.showDialog)\n }\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `Bearer ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the Spotify API\n * https://discord.com/developers/docs/resources/user#get-current-user\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(this.userInfoUrl, token)\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n\n return {\n id: body.id,\n nickName: body.display_name,\n name: body.display_name,\n email: body.email,\n avatarUrl: body.images[0]?.url || null,\n emailVerificationState: 'unsupported' as const,\n original: body,\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'access_denied'\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n\n return {\n ...user,\n token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n\n return {\n ...user,\n token: { token, type: 'bearer' as const },\n }\n }\n}\n"],"mappings":";;;;;;;AAuBO,IAAM,gBAAN,cAA4B,aAA0C;AAAA,EAoC3E,YACE,KACO,QACP;AACA,UAAM,KAAK,MAAM;AAFV;AAQP,SAAK,UAAU;AAAA,EACjB;AAAA,EA9CU,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,cAAc;AAAA;AAAA;AAAA;AAAA,EAKd,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAkBlB,yBAAyB,SAAiD;AAIlF,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;AAAA;AAAA,EAKA,MAAM,cAAc,OAAe,UAAkD;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AAEnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Oauth1Driver
3
- } from "./chunk-Y3GA4Y2H.js";
4
- import "./chunk-UF7PETXM.js";
5
- import "./chunk-CSAU5B4Q.js";
3
+ } from "../../chunk-Y3GA4Y2H.js";
4
+ import "../../chunk-UF7PETXM.js";
5
+ import "../../chunk-CSAU5B4Q.js";
6
6
 
7
7
  // src/drivers/twitter.ts
8
8
  var TwitterDriver = class extends Oauth1Driver {
@@ -98,4 +98,4 @@ var TwitterDriver = class extends Oauth1Driver {
98
98
  export {
99
99
  TwitterDriver
100
100
  };
101
- //# sourceMappingURL=twitter-QISDDK24.js.map
101
+ //# sourceMappingURL=twitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/drivers/twitter.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport {\n TwitterToken,\n AllyUserContract,\n ApiRequestContract,\n TwitterDriverConfig,\n} from '../types.js'\nimport { Oauth1Driver } from '../abstract_drivers/oauth1.js'\n\n/**\n * Twitter driver to login user via twitter\n */\nexport class TwitterDriver extends Oauth1Driver<TwitterToken, string> {\n protected requestTokenUrl = 'https://api.twitter.com/oauth/request_token'\n protected authorizeUrl = 'https://api.twitter.com/oauth/authenticate'\n protected accessTokenUrl = 'https://api.twitter.com/oauth/access_token'\n protected userInfoUrl = 'https://api.twitter.com/1.1/account/verify_credentials.json'\n\n /**\n * The query string param name for the error.\n */\n protected errorParamName = 'error'\n\n /**\n * The query string param name for the \"oauth_verifier\". Used\n * for both the post redirect value access and during the\n * time of generating the access token\n */\n protected oauthTokenVerifierName = 'oauth_verifier'\n\n /**\n * Cookie name for storing the oauth_token. The cookie\n * name for storing oauth_token_secret is derived\n * from this property\n */\n protected oauthTokenCookieName = 'twitter_oauth_token'\n\n /**\n * Param name for defined the \"oauth_token\" pre redirect\n * and also used post redirect for reading the \"oauth_token\"\n * value\n */\n protected oauthTokenParamName = 'oauth_token'\n\n /**\n * Twitter doesn't support scopes\n */\n protected scopeParamName = ''\n protected scopesSeparator = ' '\n\n constructor(\n protected ctx: HttpContext,\n public config: TwitterDriverConfig\n ) {\n super(ctx, config)\n\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Returns user info\n */\n protected async getUserInfo(\n token: string,\n secret: string,\n callback?: (request: ApiRequestContract) => void\n ) {\n const requestToken = { token, secret }\n const userInfoUrl = this.config.userInfoUrl || this.userInfoUrl\n\n const user = await this.makeSignedRequest(userInfoUrl, 'get', requestToken, (request) => {\n /**\n * Include email\n */\n request.param('include_email', true)\n\n /**\n * Parse response as JSON\n */\n request['parseAs']('json')\n\n /**\n * Invoke user callback\n */\n if (typeof callback === 'function') {\n callback(request)\n }\n })\n\n return {\n id: user.id_str,\n nickName: user.screen_name,\n name: user.name || user.screen_name,\n email: user.email,\n emailVerificationState: 'unsupported' as const,\n avatarUrl: user.profile_image_url_https.replace('_normal.jpg', '_400x400.jpg'),\n original: user,\n }\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken()\n const userInfo = await this.getUserInfo(token.token, token.secret, callback)\n\n return {\n ...userInfo,\n token,\n }\n }\n\n /**\n * Finds the user info from the \"oauth_token\" and \"oauth_token_secret\"\n * access from the access token.\n */\n async userFromTokenAndSecret(\n token: string,\n secret: string,\n callback?: (request: ApiRequestContract) => void\n ): Promise<AllyUserContract<{ token: string; secret: string }>> {\n const userInfo = await this.getUserInfo(token, secret, callback)\n\n return {\n ...userInfo,\n token: { token, secret },\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n return this.ctx.request.input('denied')\n }\n}\n"],"mappings":";;;;;;;AAqBO,IAAM,gBAAN,cAA4B,aAAmC;AAAA,EAsCpE,YACY,KACH,QACP;AACA,UAAM,KAAK,MAAM;AAHP;AACH;AAQP,SAAK,UAAU;AAAA,EACjB;AAAA,EAhDU,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,cAAc;AAAA;AAAA;AAAA;AAAA,EAKd,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjB,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOzB,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOvB,sBAAsB;AAAA;AAAA;AAAA;AAAA,EAKtB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAkB5B,MAAgB,YACd,OACA,QACA,UACA;AACA,UAAM,eAAe,EAAE,OAAO,OAAO;AACrC,UAAM,cAAc,KAAK,OAAO,eAAe,KAAK;AAEpD,UAAM,OAAO,MAAM,KAAK,kBAAkB,aAAa,OAAO,cAAc,CAAC,YAAY;AAIvF,cAAQ,MAAM,iBAAiB,IAAI;AAKnC,cAAQ,SAAS,EAAE,MAAM;AAKzB,UAAI,OAAO,aAAa,YAAY;AAClC,iBAAS,OAAO;AAAA,MAClB;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL,IAAI,KAAK;AAAA,MACT,UAAU,KAAK;AAAA,MACf,MAAM,KAAK,QAAQ,KAAK;AAAA,MACxB,OAAO,KAAK;AAAA,MACZ,wBAAwB;AAAA,MACxB,WAAW,KAAK,wBAAwB,QAAQ,eAAe,cAAc;AAAA,MAC7E,UAAU;AAAA,IACZ;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,UAAkD;AAC3D,UAAM,QAAQ,MAAM,KAAK,YAAY;AACrC,UAAM,WAAW,MAAM,KAAK,YAAY,MAAM,OAAO,MAAM,QAAQ,QAAQ;AAE3E,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,uBACJ,OACA,QACA,UAC8D;AAC9D,UAAM,WAAW,MAAM,KAAK,YAAY,OAAO,QAAQ,QAAQ;AAE/D,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,EAAE,OAAO,OAAO;AAAA,IACzB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,eAAwB;AACtB,WAAO,KAAK,IAAI,QAAQ,MAAM,QAAQ;AAAA,EACxC;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/ally",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "Social authentication provider for AdonisJS",
5
5
  "type": "module",
6
6
  "main": "build/index.js",
@@ -13,6 +13,7 @@
13
13
  "exports": {
14
14
  ".": "./build/index.js",
15
15
  "./types": "./build/src/types.js",
16
+ "./drivers/*": "./build/src/drivers/*.js",
16
17
  "./ally_provider": "./build/providers/ally_provider.js"
17
18
  },
18
19
  "engines": {
@@ -123,6 +124,7 @@
123
124
  "entry": [
124
125
  "./index.ts",
125
126
  "./src/types.ts",
127
+ "./src/drivers/*.ts",
126
128
  "./providers/ally_provider.ts"
127
129
  ],
128
130
  "outDir": "./build",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/drivers/discord.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { HttpClient } from '@poppinss/oauth-client'\n\nimport type {\n DiscordScopes,\n DiscordToken,\n ApiRequestContract,\n DiscordDriverConfig,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\n/**\n * Discord driver to login user via Discord\n */\nexport class DiscordDriver extends Oauth2Driver<DiscordToken, DiscordScopes> {\n protected accessTokenUrl = 'https://discord.com/api/oauth2/token'\n protected authorizeUrl = 'https://discord.com/api/oauth2/authorize'\n protected userInfoUrl = 'https://discord.com/api/users/@me'\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"discord_oauth_state\"\n */\n protected stateCookieName = 'discord_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from Discord\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: DiscordDriverConfig\n ) {\n super(ctx, config)\n\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<DiscordScopes>) {\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['identify', 'email'])\n\n request.param('response_type', 'code')\n request.param('grant_type', 'authorization_code')\n\n /**\n * Define params based upon user config\n */\n if (this.config.prompt) {\n request.param('prompt', this.config.prompt)\n }\n if (this.config.guildId) {\n request.param('guild_id', this.config.guildId)\n }\n if (this.config.disableGuildSelect !== undefined) {\n request.param('disable_guild_select', this.config.disableGuildSelect)\n }\n if (this.config.permissions !== undefined) {\n request.param('permissions', this.config.permissions)\n }\n }\n\n /**\n * Configuring the access token API request to send extra fields\n */\n protected configureAccessTokenRequest(request: ApiRequestContract) {\n /**\n * Send state to Discord when request is not stateles\n */\n if (!this.isStateless) {\n request.field('state', this.stateCookieValue)\n }\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `Bearer ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the Discord API\n * https://discord.com/developers/docs/resources/user#get-current-user\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token)\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n return {\n id: body.id,\n name: `${body.username}#${body.discriminator}`,\n nickName: body.username,\n avatarUrl: body.avatar\n ? `https://cdn.discordapp.com/avatars/${body.id}/${body.avatar}.${\n body.avatar.startsWith('a_') ? 'gif' : 'png'\n }`\n : `https://cdn.discordapp.com/embed/avatars/${body.discriminator % 5}.png`,\n email: body.email, // May not always be there (requires email scope)\n emailVerificationState:\n 'verified' in body\n ? body.verified\n ? ('verified' as const)\n : ('unverified' as const)\n : ('unsupported' as const),\n original: body,\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'access_denied'\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n\n return {\n ...user,\n token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n\n return {\n ...user,\n token: { token, type: 'bearer' as const },\n }\n }\n}\n"],"mappings":";;;;;;;AAwBO,IAAM,gBAAN,cAA4B,aAA0C;AAAA,EAoC3E,YACE,KACO,QACP;AACA,UAAM,KAAK,MAAM;AAFV;AAQP,SAAK,UAAU;AAAA,EACjB;AAAA,EA9CU,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,cAAc;AAAA;AAAA;AAAA;AAAA,EAKd,gBAAgB;AAAA;AAAA;AAAA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;AAC/F,QAAI,OAAO,aAAa,YAAY;AAClC,eAAS,OAAO;AAAA,IAClB;AAEA,UAAM,OAAO,MAAM,QAAQ,IAAI;AAC/B,WAAO;AAAA,MACL,IAAI,KAAK;AAAA,MACT,MAAM,GAAG,KAAK,QAAQ,IAAI,KAAK,aAAa;AAAA,MAC5C,UAAU,KAAK;AAAA,MACf,WAAW,KAAK,SACZ,sCAAsC,KAAK,EAAE,IAAI,KAAK,MAAM,IAC1D,KAAK,OAAO,WAAW,IAAI,IAAI,QAAQ,KACzC,KACA,4CAA4C,KAAK,gBAAgB,CAAC;AAAA,MACtE,OAAO,KAAK;AAAA;AAAA,MACZ,wBACE,cAAc,OACV,KAAK,WACF,aACA,eACF;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,eAAwB;AACtB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAEA,WAAO,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,UAAkD;AAC3D,UAAM,QAAQ,MAAM,KAAK,YAAY,QAAQ;AAC7C,UAAM,OAAO,MAAM,KAAK,YAAY,MAAM,OAAO,QAAQ;AAEzD,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,OAAe,UAAkD;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AAEnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/drivers/facebook.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpClient } from '@poppinss/oauth-client'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type {\n FacebookToken,\n FacebookScopes,\n LiteralStringUnion,\n ApiRequestContract,\n FacebookDriverConfig,\n FacebookProfileFields,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\n/**\n * Facebook driver to login user via Facebook\n */\nexport class FacebookDriver extends Oauth2Driver<FacebookToken, FacebookScopes> {\n protected accessTokenUrl = 'https://graph.facebook.com/v10.0/oauth/access_token'\n protected authorizeUrl = 'https://www.facebook.com/v10.0/dialog/oauth'\n protected userInfoUrl = 'https://graph.facebook.com/v10.0/me'\n\n /**\n * The default set of fields to query for the user request\n */\n protected userFields: LiteralStringUnion<FacebookProfileFields>[] = [\n 'name',\n 'first_name',\n 'last_name',\n 'link',\n 'email',\n 'picture.width(400).height(400)',\n 'verified',\n ]\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"facebok_oauth_state\"\n */\n protected stateCookieName = 'facebok_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from Facebok\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: FacebookDriverConfig\n ) {\n super(ctx, config)\n\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<FacebookScopes>) {\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['email'])\n\n request.param('response_type', 'code')\n request.param('grant_type', 'authorization_code')\n\n /**\n * Define params based upon user config\n */\n if (this.config.display) {\n request.param('display', this.config.display)\n }\n if (this.config.authType) {\n request.param('auth_type', this.config.authType)\n }\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `Bearer ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the Facebook API\n * https://developers.facebook.com/docs/graph-api/reference/user/\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token)\n request.param('fields', (this.config.userFields || this.userFields).join(','))\n\n const body = await request.get()\n\n /**\n * Invoke callback if defined\n */\n if (typeof callback === 'function') {\n callback(request)\n }\n\n return {\n id: body.id,\n name: body.name,\n nickName: body.name,\n // https://developers.facebook.com/docs/graph-api/reference/user/picture/\n avatarUrl: body.picture?.data?.url || null,\n email: body.email || null, // May not always be there (requires email scope)\n // Important note: https://developers.facebook.com/docs/facebook-login/multiple-providers#postfb1\n emailVerificationState:\n 'verified' in body\n ? body.verified\n ? ('verified' as const)\n : ('unverified' as const)\n : ('unsupported' as const),\n original: body,\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'access_denied'\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n\n return {\n ...user,\n token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n\n return {\n ...user,\n token: { token, type: 'bearer' as const },\n }\n }\n}\n"],"mappings":";;;;;;;AAyBO,IAAM,iBAAN,cAA6B,aAA4C;AAAA,EAiD9E,YACE,KACO,QACP;AACA,UAAM,KAAK,MAAM;AAFV;AAQP,SAAK,UAAU;AAAA,EACjB;AAAA,EA3DU,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,cAA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,OAAO;AAAA,IAClB;AAEA,WAAO;AAAA,MACL,IAAI,KAAK;AAAA,MACT,MAAM,KAAK;AAAA,MACX,UAAU,KAAK;AAAA;AAAA,MAEf,WAAW,KAAK,SAAS,MAAM,OAAO;AAAA,MACtC,OAAO,KAAK,SAAS;AAAA;AAAA;AAAA,MAErB,wBACE,cAAc,OACV,KAAK,WACF,aACA,eACF;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,eAAwB;AACtB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAEA,WAAO,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,UAAkD;AAC3D,UAAM,QAAQ,MAAM,KAAK,YAAY,QAAQ;AAC7C,UAAM,OAAO,MAAM,KAAK,YAAY,MAAM,OAAO,QAAQ;AAEzD,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,OAAe,UAAkD;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AAEnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/drivers/github.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { HttpClient } from '@poppinss/oauth-client'\nimport type {\n GithubToken,\n GithubScopes,\n AllyUserContract,\n GithubDriverConfig,\n ApiRequestContract,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\n/**\n * Github driver to login user via Github\n */\nexport class GithubDriver extends Oauth2Driver<GithubToken, GithubScopes> {\n protected accessTokenUrl = 'https://github.com/login/oauth/access_token'\n protected authorizeUrl = 'https://github.com/login/oauth/authorize'\n protected userInfoUrl = 'https://api.github.com/user'\n protected userEmailUrl = 'https://api.github.com/user/emails'\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"gh_oauth_state\"\n */\n protected stateCookieName = 'gh_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from Github\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: GithubDriverConfig\n ) {\n super(ctx, config)\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<GithubScopes>) {\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['user'])\n\n /**\n * Set \"allow_signup\" option when defined\n */\n if (this.config.allowSignup !== undefined) {\n request.param('allow_signup', this.config.allowSignup)\n }\n\n /**\n * Set \"login\" option when defined\n */\n if (this.config.login) {\n request.param('login', this.config.login)\n }\n }\n\n /**\n * Configuring the access token API request to send extra fields\n */\n protected configureAccessTokenRequest(request: ApiRequestContract) {\n /**\n * Send state to github when request is not stateles\n */\n if (!this.isStateless) {\n request.field('state', this.stateCookieValue)\n }\n\n /**\n * Clearing the default defined \"grant_type\". Github doesn't accept this.\n * https://github.com/poppinss/oauth-client#following-is-the-list-of-fieldsparams-set-by-the-clients-implicitly\n */\n request.clearField('grant_type')\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `token ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the Github API\n * https://docs.github.com/en/rest/reference/users#get-the-authenticated-user\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token)\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n return {\n id: body.id,\n nickName: body.name,\n email: body.email, // May not always be there\n emailVerificationState: (body.email\n ? 'verified'\n : 'unsupported') as AllyUserContract<any>['emailVerificationState'],\n name: body.name,\n avatarUrl: body.avatar_url,\n original: body,\n }\n }\n\n /**\n * Fetches the user email from the Github API.\n * https://docs.github.com/en/rest/reference/users#list-email-addresses-for-the-authenticated-user\n */\n protected async getUserEmail(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(\n this.config.userEmailUrl || this.userEmailUrl,\n token\n )\n\n if (typeof callback === 'function') {\n callback(request)\n }\n\n try {\n let emails = await request.get()\n\n /**\n * Sort emails to keep the primary ones on the top\n */\n emails = emails.sort((email: any) => (email.primary ? -1 : 1))\n\n /**\n * Get the first verified email of the user\n */\n let mainEmail = emails.find((email: any) => email.verified)\n\n /**\n * If there are no verified emails, then get any first one\n */\n if (!mainEmail) {\n mainEmail = emails[0]\n }\n\n return mainEmail\n } catch (error) {\n if (error && error.response && error.response.statusCode === 404) {\n return\n }\n throw error\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'access_denied'\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n\n /**\n * Fetch email separately\n */\n if (!user.email) {\n this.ctx.logger.trace('Fetching github user email separately')\n\n const emailResponse = await this.getUserEmail(token.token, callback)\n if (emailResponse) {\n user.email = emailResponse.email\n user.emailVerificationState = emailResponse.verified\n ? ('verified' as const)\n : ('unverified' as const)\n }\n }\n\n return {\n ...user,\n token: token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n\n /**\n * Fetch email separately\n */\n if (!user.email) {\n this.ctx.logger.trace('Fetching github user email separately')\n\n const emailResponse = await this.getUserEmail(token, callback)\n if (emailResponse) {\n user.email = emailResponse.email\n user.emailVerificationState = emailResponse.verified\n ? ('verified' as const)\n : ('unverified' as const)\n }\n }\n\n return {\n ...user,\n token: { token, type: 'bearer' as const },\n }\n }\n}\n"],"mappings":";;;;;;;AAwBO,IAAM,eAAN,cAA2B,aAAwC;AAAA,EAqCxE,YACE,KACO,QACP;AACA,UAAM,KAAK,MAAM;AAFV;AAOP,SAAK,UAAU;AAAA,EACjB;AAAA,EA9CU,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,eAAe;AAAA;AAAA;AAAA;AAAA,EAKf,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAiBlB,yBAAyB,SAAgD;AAIjF,YAAQ,OAAO,KAAK,OAAO,UAAU,CAAC,MAAM,CAAC;AAK7C,QAAI,KAAK,OAAO,gBAAgB,QAAW;AACzC,cAAQ,MAAM,gBAAgB,KAAK,OAAO,WAAW;AAAA,IACvD;AAKA,QAAI,KAAK,OAAO,OAAO;AACrB,cAAQ,MAAM,SAAS,KAAK,OAAO,KAAK;AAAA,IAC1C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKU,4BAA4B,SAA6B;AAIjE,QAAI,CAAC,KAAK,aAAa;AACrB,cAAQ,MA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,YAAY,MAAM,SAAS,eAAe,KAAK;AAChE;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,eAAwB;AACtB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAEA,WAAO,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,UAAkD;AAC3D,UAAM,QAAQ,MAAM,KAAK,YAAY,QAAQ;AAC7C,UAAM,OAAO,MAAM,KAAK,YAAY,MAAM,OAAO,QAAQ;AAKzD,QAAI,CAAC,KAAK,OAAO;AACf,WAAK,IAAI,OAAO,MAAM,uCAAuC;AAE7D,YAAM,gBAAgB,MAAM,KAAK,aAAa,MAAM,OAAO,QAAQ;AACnE,UAAI,eAAe;AACjB,aAAK,QAAQ,cAAc;AAC3B,aAAK,yBAAyB,cAAc,WACvC,aACA;AAAA,MACP;AAAA,IACF;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,OAAe,UAAkD;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AAKnD,QAAI,CAAC,KAAK,OAAO;AACf,WAAK,IAAI,OAAO,MAAM,uCAAuC;AAE7D,YAAM,gBAAgB,MAAM,KAAK,aAAa,OAAO,QAAQ;AAC7D,UAAI,eAAe;AACjB,aAAK,QAAQ,cAAc;AAC3B,aAAK,yBAAyB,cAAc,WACvC,aACA;AAAA,MACP;AAAA,IACF;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/drivers/google.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { HttpClient } from '@poppinss/oauth-client'\nimport type {\n GoogleToken,\n GoogleScopes,\n GoogleDriverConfig,\n ApiRequestContract,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\nconst SCOPE_PREFIXES = {\n 'https://www.googleapis.com/auth': [\n 'userinfo.email',\n 'userinfo.profile',\n 'contacts',\n 'contacts.other.readonly',\n 'contacts.readonly',\n 'directory.readonly',\n 'user.addresses.read',\n 'user.birthday.read',\n 'user.emails.read',\n 'user.gender.read',\n 'user.organization.read',\n 'user.phonenumbers.read',\n 'analytics',\n 'analytics.readonly',\n 'documents',\n 'documents.readonly',\n 'forms',\n 'forms.currentonly',\n 'groups',\n 'spreadsheets',\n 'calendar',\n 'calendar.events',\n 'calendar.events.readonly',\n 'calendar.readonly',\n 'calendar.settings.readonly',\n 'drive',\n 'drive.appdata',\n 'drive.file',\n 'drive.metadata',\n 'drive.metadata.readonly',\n 'drive.photos.readonly',\n 'drive.readonly',\n 'drive.scripts',\n ],\n}\n\n/**\n * Google driver to login user via Google\n */\nexport class GoogleDriver extends Oauth2Driver<GoogleToken, GoogleScopes> {\n protected accessTokenUrl = 'https://oauth2.googleapis.com/token'\n protected authorizeUrl = 'https://accounts.google.com/o/oauth2/v2/auth'\n protected userInfoUrl = 'https://www.googleapis.com/oauth2/v3/userinfo'\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"google_oauth_state\"\n */\n protected stateCookieName = 'google_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from google\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: GoogleDriverConfig\n ) {\n super(ctx, config)\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<GoogleScopes>) {\n request.transformScopes((scopes) => this.buildScopes(scopes))\n\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['openid', 'userinfo.email', 'userinfo.profile'])\n\n /**\n * Set \"response_type\" param\n */\n request.param('response_type', 'code')\n\n /**\n * Define params based upon user config\n */\n if (this.config.accessType) {\n request.param('access_type', this.config.accessType)\n }\n if (this.config.prompt) {\n request.param('prompt', this.config.prompt)\n }\n if (this.config.display) {\n request.param('display', this.config.display)\n }\n if (this.config.hostedDomain) {\n request.param('hd', this.config.hostedDomain)\n }\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `Bearer ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the Google API\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(this.config.userInfoUrl || this.userInfoUrl, token)\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n\n return {\n id: body.sub,\n nickName: body.name,\n name: body.name,\n email: body.email,\n avatarUrl: body.picture,\n emailVerificationState: body.email_verified ? ('verified' as const) : ('unverified' as const),\n original: body,\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'access_denied'\n }\n\n /**\n * Get access token\n */\n async accessToken(callback?: (request: ApiRequestContract) => void): Promise<GoogleToken> {\n const token = await super.accessToken(callback)\n\n return {\n ...token,\n idToken: token.id_token,\n }\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n\n return {\n ...user,\n token: token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n\n return {\n ...user,\n token: { token, type: 'bearer' as const },\n }\n }\n\n /**\n * Prefixes google scopes with the url\n */\n buildScopes(scopes: string[]) {\n return scopes.map((name) => {\n const prefix = Object.keys(SCOPE_PREFIXES).find((one) =>\n SCOPE_PREFIXES[one as keyof typeof SCOPE_PREFIXES].includes(name)\n )\n return prefix ? `${prefix}/${name}` : name\n })\n }\n}\n"],"mappings":";;;;;;;AAoBA,IAAM,iBAAiB;AAAA,EACrB,mCAAmC;AAAA,IACjC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAKO,IAAM,eAAN,cAA2B,aAAwC;AAAA,EAoCxE,YACE,KACO,QACP;AACA,UAAM,KAAK,MAAM;AAFV;AAOP,SAAK,UAAU;AAAA,EACjB;AAAA,EA7CU,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,cAAc;AAAA;AAAA;AAAA;AAAA,EAKd,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBA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AAA;AAAA;AAAA;AAAA,EAKA,eAAwB;AACtB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAEA,WAAO,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,YAAY,UAAwE;AACxF,UAAM,QAAQ,MAAM,MAAM,YAAY,QAAQ;AAE9C,WAAO;AAAA,MACL,GAAG;AAAA,MACH,SAAS,MAAM;AAAA,IACjB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,UAAkD;AAC3D,UAAM,QAAQ,MAAM,KAAK,YAAY,QAAQ;AAC7C,UAAM,OAAO,MAAM,KAAK,YAAY,MAAM,OAAO,QAAQ;AAEzD,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,OAAe,UAAkD;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AAEnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,QAAkB;AAC5B,WAAO,OAAO,IAAI,CAAC,SAAS;AAC1B,YAAM,SAAS,OAAO,KAAK,cAAc,EAAE;AAAA,QAAK,CAAC,QAC/C,eAAe,GAAkC,EAAE,SAAS,IAAI;AAAA,MAClE;AACA,aAAO,SAAS,GAAG,MAAM,IAAI,IAAI,KAAK;AAAA,IACxC,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/drivers/linked_in.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { Exception } from '@poppinss/utils'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { HttpClient } from '@poppinss/oauth-client'\nimport type {\n LinkedInToken,\n LinkedInScopes,\n ApiRequestContract,\n LinkedInDriverConfig,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\n/**\n * LinkedIn driver to login user via LinkedIn\n */\nexport class LinkedInDriver extends Oauth2Driver<LinkedInToken, LinkedInScopes> {\n protected accessTokenUrl = 'https://www.linkedin.com/oauth/v2/accessToken'\n protected authorizeUrl = 'https://www.linkedin.com/oauth/v2/authorization'\n protected userInfoUrl = 'https://api.linkedin.com/v2/me'\n protected userEmailUrl = 'https://api.linkedin.com/v2/clientAwareMemberHandles'\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"linkedin_oauth_state\"\n */\n protected stateCookieName = 'linkedin_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from linkedin\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: LinkedInDriverConfig\n ) {\n super(ctx, config)\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<LinkedInScopes>) {\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['r_emailaddress', 'r_liteprofile'])\n\n /**\n * Set \"response_type\" param\n */\n request.param('response_type', 'code')\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `Bearer ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the LinkedIn API\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n let url = this.config.userInfoUrl || this.userInfoUrl\n const request = this.getAuthenticatedRequest(url, token)\n request.param(\n 'projection',\n '(id,localizedLastName,localizedFirstName,vanityName,profilePicture(displayImage~digitalmediaAsset:playableStreams))'\n )\n\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n\n /**\n * Finding the user avatar\n */\n let avatar: string = ''\n if (body.profilePicture) {\n const avatars = body.profilePicture['displayImage~']['elements'] || []\n if (avatars.length && avatars[0].identifiers && avatars[0].identifiers.length) {\n avatar = avatars[0].identifiers[0].identifier\n }\n }\n\n return {\n id: body.id,\n nickName: body.vanityName || `${body.localizedFirstName} ${body.localizedLastName}`,\n name: `${body.localizedFirstName} ${body.localizedLastName}`,\n avatarUrl: avatar,\n original: body,\n }\n }\n\n /**\n * Fetches the user email from the LinkedIn API\n */\n protected async getUserEmail(token: string, callback?: (request: ApiRequestContract) => void) {\n let url = this.config.userEmailUrl || this.userEmailUrl\n const request = this.getAuthenticatedRequest(url, token)\n request.param('q', 'members')\n request.param('projection', '(elements*(primary,type,handle~))')\n\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n let mainEmail = body.elements.find((resource: any) => {\n return resource.type === 'EMAIL' && resource['handle~']\n })\n\n /**\n * We except email to always exist\n */\n if (!mainEmail) {\n throw new Exception(\n 'Cannot request user email. Make sure you are using the \"r_emailaddress\" scope'\n )\n }\n\n return mainEmail['handle~']['emailAddress']\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'user_cancelled_login' || error === 'user_cancelled_authorize'\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n const email = await this.getUserEmail(token.token, callback)\n\n return {\n ...user,\n email: email,\n emailVerificationState: 'unsupported' as const,\n token: token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n const email = await this.getUserEmail(token, callback)\n\n return {\n ...user,\n email: email,\n emailVerificationState: 'unsupported' as const,\n token: { token, type: 'bearer' as const },\n }\n }\n}\n"],"mappings":";;;;;;;AASA,SAAS,iBAAiB;AAenB,IAAM,iBAAN,cAA6B,aAA4C;AAAA,EAqC9E,YACE,KACO,QACP;AACA,UAAM,KAAK,MAAM;AAFV;AAOP,SAAK,UAAU;AAAA,EACjB;AAAA,EA9CU,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,eAAe;AAAA;AAAA;AAAA;AAAA,EAKf,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAiBlB,yBAAyB,SAAkD;AAInF,YAAQ,OAAO,KAAK,OAAO,UAAU,CAAC,kBAAkB,eAAe,CAAC;AAKxE,YAAQ,MAAM,iBAAiB,MAAM;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,EAKU,wBAAwB,KAAa,OAA2B;AACxE,UAAM,UAAU,KAAK,WAAW,GAAG;AACnC,YAAQ,OAAO,iBAAiB,UAAU,KAAK,EAAE;AACjD,YAAQ,OAAO,UAAU,kBAAkB;AAC3C,YAAQ,QAAQ,MAAM;AACtB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAgB,YAAY,OAAe,UAAkD;AAC3F,QAAI,MAAM,KAAK,OAAO,eAAe,KAAK;AAC1C,UAAM,UAAU,KAAK,wBAAwB,KAAK,KAAK;AACvD,YAAQ;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAEA,QAAI,OA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AAEA,WAAO,UAAU,0BAA0B,UAAU;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,UAAkD;AAC3D,UAAM,QAAQ,MAAM,KAAK,YAAY,QAAQ;AAC7C,UAAM,OAAO,MAAM,KAAK,YAAY,MAAM,OAAO,QAAQ;AACzD,UAAM,QAAQ,MAAM,KAAK,aAAa,MAAM,OAAO,QAAQ;AAE3D,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,MACA,wBAAwB;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,OAAe,UAAkD;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AACnD,UAAM,QAAQ,MAAM,KAAK,aAAa,OAAO,QAAQ;AAErD,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,MACA,wBAAwB;AAAA,MACxB,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/drivers/spotify.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { HttpClient } from '@poppinss/oauth-client'\nimport type {\n SpotifyScopes,\n SpotifyToken,\n ApiRequestContract,\n SpotifyDriverConfig,\n RedirectRequestContract,\n} from '../types.js'\nimport { Oauth2Driver } from '../abstract_drivers/oauth2.js'\n\n/**\n * Spotify driver to login user via Spotify\n */\nexport class SpotifyDriver extends Oauth2Driver<SpotifyToken, SpotifyScopes> {\n protected accessTokenUrl = 'https://accounts.spotify.com/api/token'\n protected authorizeUrl = 'https://accounts.spotify.com/authorize'\n protected userInfoUrl = 'https://api.spotify.com/v1/me'\n\n /**\n * The param name for the authorization code\n */\n protected codeParamName = 'code'\n\n /**\n * The param name for the error\n */\n protected errorParamName = 'error'\n\n /**\n * Cookie name for storing the \"spotify_oauth_state\"\n */\n protected stateCookieName = 'spotify_oauth_state'\n\n /**\n * Parameter name to be used for sending and receiving the state\n * from Spotify\n */\n protected stateParamName = 'state'\n\n /**\n * Parameter name for defining the scopes\n */\n protected scopeParamName = 'scope'\n\n /**\n * Scopes separator\n */\n protected scopesSeparator = ' '\n\n constructor(\n ctx: HttpContext,\n public config: SpotifyDriverConfig\n ) {\n super(ctx, config)\n\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Configuring the redirect request with defaults\n */\n protected configureRedirectRequest(request: RedirectRequestContract<SpotifyScopes>) {\n /**\n * Define user defined scopes or the default one's\n */\n request.scopes(this.config.scopes || ['user-read-email'])\n\n request.param('response_type', 'code')\n request.param('grant_type', 'authorization_code')\n\n /**\n * Define params based upon user config\n */\n if (this.config.showDialog) {\n request.param('show_dialog', this.config.showDialog)\n }\n }\n\n /**\n * Returns the HTTP request with the authorization header set\n */\n protected getAuthenticatedRequest(url: string, token: string): HttpClient {\n const request = this.httpClient(url)\n request.header('Authorization', `Bearer ${token}`)\n request.header('Accept', 'application/json')\n request.parseAs('json')\n return request\n }\n\n /**\n * Fetches the user info from the Spotify API\n * https://discord.com/developers/docs/resources/user#get-current-user\n */\n protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {\n const request = this.getAuthenticatedRequest(this.userInfoUrl, token)\n if (typeof callback === 'function') {\n callback(request)\n }\n\n const body = await request.get()\n\n return {\n id: body.id,\n nickName: body.display_name,\n name: body.display_name,\n email: body.email,\n avatarUrl: body.images[0]?.url || null,\n emailVerificationState: 'unsupported' as const,\n original: body,\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n const error = this.getError()\n if (!error) {\n return false\n }\n\n return error === 'access_denied'\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken(callback)\n const user = await this.getUserInfo(token.token, callback)\n\n return {\n ...user,\n token,\n }\n }\n\n /**\n * Finds the user by the access token\n */\n async userFromToken(token: string, callback?: (request: ApiRequestContract) => void) {\n const user = await this.getUserInfo(token, callback)\n\n return {\n ...user,\n token: { token, type: 'bearer' as const },\n }\n }\n}\n"],"mappings":";;;;;;;AAuBO,IAAM,gBAAN,cAA4B,aAA0C;AAAA,EAoC3E,YACE,KACO,QACP;AACA,UAAM,KAAK,MAAM;AAFV;AAQP,SAAK,UAAU;AAAA,EACjB;AAAA,EA9CU,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,cAAc;AAAA;AAAA;AAAA;AAAA,EAKd,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKjB,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAkBlB,yBAAyB,SAAiD;AAIlF,YAAQ,OAAO,KAAK,OAAO,UAAU,CAAC,iBAAiB,CAAC;AAExD,YAAQ,MAAM,iBAAiB,MAAM;AACrC,YAAQ,MAAM,cAAc,oBAAoB;AAKhD,QAAI,KAAK,OAAO,YAAY;AAC1B,cAAQ,MAAM,eAAe,KAAK,OAAO,UAAU;AAAA,IACrD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKU,wBAAwB,KAAa,OAA2B;AACxE,UAAM,UAAU,KAAK,WAAW,GAAG;AACnC,YAAQ,OAAO,iBAAiB,UAAU,KAAK,EAAE;AACjD,YAAQ,OAAO,UAAU,kBAAkB;AAC3C,YAAQ,QAAQ,MAAM;AACtB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAgB,YAAY,OAAe,UAAkD;AAC3F,UAAM,UAAU,KAAK,wBAAwB,KAAK,aAAa,KAAK;AACpE,QAAI,OAAO,aAAa,YAAY;AAClC,eAAS,OAAO;AAAA,IAClB;AAEA,UAAM,OAAO,MAAM,QAAQ,IAAI;AAE/B,WAAO;AAAA,MACL,IAAI,KAAK;AAAA,MACT,UAAU,KAAK;AAAA,MACf,MAAM,KAAK;AAAA,MACX,OAAO,KAAK;AAAA,MACZ,WAAW,KAAK,OAAO,CAAC,GAAG,OAAO;AAAA,MAClC,wBAAwB;AAAA,MACxB,UAAU;AAAA,IACZ;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,eAAwB;AACtB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAEA,WAAO,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,UAAkD;AAC3D,UAAM,QAAQ,MAAM,KAAK,YAAY,QAAQ;AAC7C,UAAM,OAAO,MAAM,KAAK,YAAY,MAAM,OAAO,QAAQ;AAEzD,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,OAAe,UAAkD;AACnF,UAAM,OAAO,MAAM,KAAK,YAAY,OAAO,QAAQ;AAEnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,OAAO,EAAE,OAAO,MAAM,SAAkB;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/drivers/twitter.ts"],"sourcesContent":["/*\n * @adonisjs/ally\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport {\n TwitterToken,\n AllyUserContract,\n ApiRequestContract,\n TwitterDriverConfig,\n} from '../types.js'\nimport { Oauth1Driver } from '../abstract_drivers/oauth1.js'\n\n/**\n * Twitter driver to login user via twitter\n */\nexport class TwitterDriver extends Oauth1Driver<TwitterToken, string> {\n protected requestTokenUrl = 'https://api.twitter.com/oauth/request_token'\n protected authorizeUrl = 'https://api.twitter.com/oauth/authenticate'\n protected accessTokenUrl = 'https://api.twitter.com/oauth/access_token'\n protected userInfoUrl = 'https://api.twitter.com/1.1/account/verify_credentials.json'\n\n /**\n * The query string param name for the error.\n */\n protected errorParamName = 'error'\n\n /**\n * The query string param name for the \"oauth_verifier\". Used\n * for both the post redirect value access and during the\n * time of generating the access token\n */\n protected oauthTokenVerifierName = 'oauth_verifier'\n\n /**\n * Cookie name for storing the oauth_token. The cookie\n * name for storing oauth_token_secret is derived\n * from this property\n */\n protected oauthTokenCookieName = 'twitter_oauth_token'\n\n /**\n * Param name for defined the \"oauth_token\" pre redirect\n * and also used post redirect for reading the \"oauth_token\"\n * value\n */\n protected oauthTokenParamName = 'oauth_token'\n\n /**\n * Twitter doesn't support scopes\n */\n protected scopeParamName = ''\n protected scopesSeparator = ' '\n\n constructor(\n protected ctx: HttpContext,\n public config: TwitterDriverConfig\n ) {\n super(ctx, config)\n\n /**\n * Extremely important to call the following method to clear the\n * state set by the redirect request\n */\n this.loadState()\n }\n\n /**\n * Returns user info\n */\n protected async getUserInfo(\n token: string,\n secret: string,\n callback?: (request: ApiRequestContract) => void\n ) {\n const requestToken = { token, secret }\n const userInfoUrl = this.config.userInfoUrl || this.userInfoUrl\n\n const user = await this.makeSignedRequest(userInfoUrl, 'get', requestToken, (request) => {\n /**\n * Include email\n */\n request.param('include_email', true)\n\n /**\n * Parse response as JSON\n */\n request['parseAs']('json')\n\n /**\n * Invoke user callback\n */\n if (typeof callback === 'function') {\n callback(request)\n }\n })\n\n return {\n id: user.id_str,\n nickName: user.screen_name,\n name: user.name || user.screen_name,\n email: user.email,\n emailVerificationState: 'unsupported' as const,\n avatarUrl: user.profile_image_url_https.replace('_normal.jpg', '_400x400.jpg'),\n original: user,\n }\n }\n\n /**\n * Returns details for the authorized user\n */\n async user(callback?: (request: ApiRequestContract) => void) {\n const token = await this.accessToken()\n const userInfo = await this.getUserInfo(token.token, token.secret, callback)\n\n return {\n ...userInfo,\n token,\n }\n }\n\n /**\n * Finds the user info from the \"oauth_token\" and \"oauth_token_secret\"\n * access from the access token.\n */\n async userFromTokenAndSecret(\n token: string,\n secret: string,\n callback?: (request: ApiRequestContract) => void\n ): Promise<AllyUserContract<{ token: string; secret: string }>> {\n const userInfo = await this.getUserInfo(token, secret, callback)\n\n return {\n ...userInfo,\n token: { token, secret },\n }\n }\n\n /**\n * Find if the current error code is for access denied\n */\n accessDenied(): boolean {\n return this.ctx.request.input('denied')\n }\n}\n"],"mappings":";;;;;;;AAqBO,IAAM,gBAAN,cAA4B,aAAmC;AAAA,EAsCpE,YACY,KACH,QACP;AACA,UAAM,KAAK,MAAM;AAHP;AACH;AAQP,SAAK,UAAU;AAAA,EACjB;AAAA,EAhDU,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,cAAc;AAAA;AAAA;AAAA;AAAA,EAKd,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjB,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOzB,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOvB,sBAAsB;AAAA;AAAA;AAAA;AAAA,EAKtB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAkB5B,MAAgB,YACd,OACA,QACA,UACA;AACA,UAAM,eAAe,EAAE,OAAO,OAAO;AACrC,UAAM,cAAc,KAAK,OAAO,eAAe,KAAK;AAEpD,UAAM,OAAO,MAAM,KAAK,kBAAkB,aAAa,OAAO,cAAc,CAAC,YAAY;AAIvF,cAAQ,MAAM,iBAAiB,IAAI;AAKnC,cAAQ,SAAS,EAAE,MAAM;AAKzB,UAAI,OAAO,aAAa,YAAY;AAClC,iBAAS,OAAO;AAAA,MAClB;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL,IAAI,KAAK;AA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