Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async (req: IncomingMessage, res: ServerResponse, options: LoginOptions = {}): Promise => {
if (!res) {
throw new Error('Response is not available');
}
const { state = base64url(randomBytes(48)), ...authParams } = (options && options.authParams) || {};
// Create the authorization url.
const client = await clientProvider();
const authorizationUrl = client.authorizationUrl({
redirect_uri: settings.redirectUri,
scope: settings.scope,
response_type: 'code',
audience: settings.audience,
state,
auth0Client: telemetry(),
...authParams
});
// Set the necessary cookies
setCookies(req, res, [
{
async createSetModeToken(mode, accessPeriod, from = Date.now()) {
const idData = {
mode,
createdBy: this.account.address,
validUntil: Math.floor(from / 1000) + accessPeriod
};
return base64url(this.serializeForHashing({
signature: this.account.sign(this.serializeForHashing(idData)).signature,
idData
}));
}
useDebounce(() => {
if (!link) return
const key = base64url(link)
setLoading(true)
lastKey += 1;
((currentKey) => {
axios.get(`https://json.xyz/${key}`).then(({ data }) => {
if (currentKey !== lastKey) return
setLoading(false)
setClosed(false)
setInfo(data)
onData(data)
}).catch(() => {
if (currentKey !== lastKey) return
setLoading(false)
setClosed(true)
})
})(lastKey)
}, 800, [link])
export const generateURLSafeToken = size => base64url(crypto.randomBytes(size));
async function snapshotFetch(url: string | Request | URL): Promise {
const snapshotDir = "src/plugins/discourse/snapshots";
const filename = base64url(url);
const file = path.join(snapshotDir, filename);
if (await fs.exists(file)) {
const contents = await fs.readFile(file);
return new Response(contents, {status: 200});
} else {
throw new Error(`couldn't load snapshot for ${file}`);
}
}
export const snapshotFetcher = () => new Fetcher(options, snapshotFetch, 0);
function createLoginUrlWithVerifier() {
const verifier = base64url(uuidv4());
const challenge = base64url(
crypto
.createHash('sha256')
.update(verifier)
.digest()
);
const loginUrl = `${authDomain}/oauth2/authorize?${new URLSearchParams({
...authParams,
redirect_uri: getRedirectUrl(),
code_challenge: challenge,
code_challenge_method: 'S256',
}).toString()}`;
return { loginUrl, verifier };
}
function createLoginUrlWithVerifier() {
const verifier = base64url(uuidv4());
const challenge = base64url(
crypto
.createHash('sha256')
.update(verifier)
.digest()
);
const loginUrl = `${authDomain}/oauth2/authorize?${new URLSearchParams({
...authParams,
redirect_uri: getRedirectUrl(),
code_challenge: challenge,
code_challenge_method: 'S256',
}).toString()}`;
return { loginUrl, verifier };
}