@docusign/iam-sdk
Version:
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@docusign/iam-sdk* API.
85 lines • 3.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthorizationUrlParamsSchema = void 0;
exports.createAuthorizationUrl = createAuthorizationUrl;
const zod_1 = require("zod");
const scopes_js_1 = require("./scopes.js");
const types_js_1 = require("./types.js");
/**
* Schema for authorization URL options.
*/
exports.AuthorizationUrlParamsSchema = zod_1.z.object({
/**
* The type of response to request.
*
* Use `code` for authorization code flows, and `token` for implicit flows.
*
* @link https://developers.docusign.com/platform/auth/consent/obtaining-individual-consent/
*/
type: zod_1.z.enum(["code", "token"]),
/**
* The environment to use for the OAuth flow.
*
* Use `account-d-docusign.com` for demo and `account.docusign.com` for
* production.
*
* If no environment is provided, the default is `account-d.docusign.com`.
*/
oauthBasePath: types_js_1.DocusignOAuthBasePathSchema.optional().default("account-d.docusign.com"),
/** Client ID (AKA Integration Key) */
clientId: zod_1.z.string(),
/**
* The URI where the user will be redirected after authorization.
*
* This must match one of the redirect URIs configured for your integration.
*/
redirectUri: zod_1.z.string().url(),
/**
* Scopes for the OAuth flow.
*
* If no scopes are provided, all available scopes will be used.
*
* @link https://developers.docusign.com/platform/auth/scopes/
*/
scopes: zod_1.z
.string()
.array()
.readonly()
.optional()
.default(scopes_js_1.DOCUSIGN_IAM_OAUTH_SCOPES),
/**
* An opaque value used to maintain state between the request and callback.
*
* This parameter is used to prevent cross-site request forgery.
*/
state: zod_1.z.string().optional(),
/**
* The coptionsode challenge for PKCE.
*
* A Base64-URL-encoded string derived from the code verifier.
* Used in authorization code flow with PKCE for public clients.
*/
codeChallenge: zod_1.z.string().optional(),
});
/**
* Creates an authorization URL for the Docusign OAuth flows.
*
* @link https://developers.docusign.com/platform/auth/consent/obtaining-individual-consent/
*/
function createAuthorizationUrl(options) {
const { type, clientId, redirectUri, scopes, state, codeChallenge, oauthBasePath, } = exports.AuthorizationUrlParamsSchema.parse(options);
let uri = `https://${oauthBasePath}/oauth/auth`;
uri += `?response_type=${encodeURIComponent(type)}`;
uri += `&client_id=${encodeURIComponent(clientId)}`;
uri += `&scope=${encodeURIComponent(scopes.join(" "))}`;
uri += `&redirect_uri=${encodeURIComponent(redirectUri)}`;
if (state) {
uri += `&state=${encodeURIComponent(state)}`;
}
if (codeChallenge) {
uri += `&code_challenge=${encodeURIComponent(codeChallenge)}`;
uri += `&code_challenge_method=S256`;
}
return uri;
}
//# sourceMappingURL=authorization-url.js.map