UNPKG

@adonisjs/ally

Version:

Social authentication provider for AdonisJS

83 lines (80 loc) 2.16 kB
import { __export } from "./chunk-PZ5AY32C.js"; // src/errors.ts var errors_exports = {}; __export(errors_exports, { E_OAUTH_MISSING_CODE: () => E_OAUTH_MISSING_CODE, E_OAUTH_STATE_MISMATCH: () => E_OAUTH_STATE_MISMATCH }); import { createError } from "@poppinss/utils"; var E_OAUTH_MISSING_CODE = createError( 'Cannot request access token. Redirect request is missing the "%s" param', "E_OAUTH_MISSING_CODE", 500 ); var E_OAUTH_STATE_MISMATCH = createError( "Unable to verify re-redirect state", "E_OAUTH_STATE_MISMATCH", 400 ); // src/redirect_request.ts import { UrlBuilder } from "@poppinss/oauth-client"; var RedirectRequest = class extends UrlBuilder { #scopesTransformer; #scopeParamName; #scopeSeparator; constructor(baseUrl, scopeParamName, scopeSeparator) { super(baseUrl); this.#scopeParamName = scopeParamName; this.#scopeSeparator = scopeSeparator; } /** * Register a custom function to transform scopes. Exposed for drivers * to implement. */ transformScopes(callback) { this.#scopesTransformer = callback; return this; } /** * Define an array of scopes. */ scopes(scopes) { if (typeof this.#scopesTransformer === "function") { scopes = this.#scopesTransformer(scopes); } this.param(this.#scopeParamName, scopes.join(this.#scopeSeparator)); return this; } /** * Merge to existing scopes */ mergeScopes(scopes) { if (typeof this.#scopesTransformer === "function") { scopes = this.#scopesTransformer(scopes); } const existingScopes = this.getParams()[this.#scopeParamName]; const scopesString = scopes.join(this.#scopeSeparator); if (!existingScopes) { this.param(this.#scopeParamName, scopesString); return this; } this.param(this.#scopeParamName, `${existingScopes}${this.#scopeSeparator}${scopesString}`); return this; } /** * Clear existing scopes */ clearScopes() { this.clearParam(this.#scopeParamName); return this; } }; export { E_OAUTH_MISSING_CODE, E_OAUTH_STATE_MISMATCH, errors_exports, RedirectRequest }; //# sourceMappingURL=chunk-N72DEJC2.js.map