slack-edge
Version:
Slack app development framework for edge functions with streamlined TypeScript support
79 lines • 3.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultOnStateValidationError = defaultOnStateValidationError;
exports.defaultOnFailure = defaultOnFailure;
exports.defaultOAuthStart = defaultOAuthStart;
exports.defaultOAuthCallback = defaultOAuthCallback;
const error_codes_1 = require("./error-codes");
const oauth_page_renderer_1 = require("./oauth-page-renderer");
/**
* The default onStateValidationError implementation.
*/
function defaultOnStateValidationError(renderer) {
return async ({ startPath }) => {
const renderPage = renderer ?? oauth_page_renderer_1.renderDefaultOAuthErrorPage;
return new Response(await renderPage({
installPath: startPath,
reason: error_codes_1.InvalidStateParameter,
}), {
status: 400,
headers: { "Content-Type": "text/html; charset=utf-8" },
});
};
}
/**
* The default onFailure implementation.
* @param startPath the path to start the OAuth flow again
* @param reason the error reason code
* @returns response
*/
function defaultOnFailure(renderer) {
return async ({ startPath, reason }) => {
const renderPage = renderer ?? oauth_page_renderer_1.renderDefaultOAuthErrorPage;
return new Response(await renderPage({ installPath: startPath, reason }), {
status: 400,
headers: { "Content-Type": "text/html; charset=utf-8" },
});
};
}
/**
* The default OAuthStart implementation.
*/
function defaultOAuthStart(startImmediateRedirect, renderer) {
return async ({ authorizeUrl, stateCookieName, stateValue }) => {
const immediateRedirect = startImmediateRedirect !== false;
const status = immediateRedirect ? 302 : 200;
const renderPage = renderer ?? oauth_page_renderer_1.renderDefaultOAuthStartPage;
return new Response(await renderPage({ immediateRedirect, url: authorizeUrl }), {
status,
headers: {
Location: authorizeUrl,
"Set-Cookie": `${stateCookieName}=${stateValue}; Secure; HttpOnly; Path=/; Max-Age=300`,
"Content-Type": "text/html; charset=utf-8",
},
});
};
}
/**
* The default OAuthCallback implementation.
*/
function defaultOAuthCallback(renderer) {
return async ({ oauthAccess, enterpriseUrl, stateCookieName, installation, authTestResponse }) => {
const renderPage = renderer ?? oauth_page_renderer_1.renderDefaultOAuthCompletionPage;
return new Response(await renderPage({
appId: oauthAccess.app_id,
teamId: oauthAccess.team?.id,
isEnterpriseInstall: oauthAccess.is_enterprise_install,
enterpriseUrl,
installation,
authTestResponse,
}), {
status: 200,
headers: {
"Set-Cookie": `${stateCookieName}=deleted; Secure; HttpOnly; Path=/; Max-Age=0`,
"Content-Type": "text/html; charset=utf-8",
},
});
};
}
//# sourceMappingURL=hook.js.map