fix(core): Use correct scopes-separator when generating authorization urls (#6502)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-06-21 15:19:38 +02:00
committed by GitHub
parent 6ab350209d
commit 5bf83f8bf6
8 changed files with 53 additions and 57 deletions

View File

@@ -2,17 +2,21 @@
/* eslint-disable @typescript-eslint/restrict-plus-operands */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { ClientOAuth2RequestObject } from './ClientOAuth2';
import type { ClientOAuth2Options, ClientOAuth2RequestObject } from './ClientOAuth2';
import { ERROR_RESPONSES } from './constants';
/**
* Check if properties exist on an object and throw when they aren't.
*/
export function expects(obj: any, ...args: any[]) {
for (let i = 1; i < args.length; i++) {
const prop = args[i];
if (obj[prop] === null) {
throw new TypeError('Expected "' + prop + '" to exist');
export function expects<Keys extends keyof ClientOAuth2Options>(
obj: ClientOAuth2Options,
...keys: Keys[]
): asserts obj is ClientOAuth2Options & {
[K in Keys]: NonNullable<ClientOAuth2Options[K]>;
} {
for (const key of keys) {
if (obj[key] === null || obj[key] === undefined) {
throw new TypeError('Expected "' + key + '" to exist');
}
}
}
@@ -47,13 +51,6 @@ function toString(str: string | null | undefined) {
return str === null ? '' : String(str);
}
/**
* Sanitize the scopes option to be a string.
*/
export function sanitizeScope(scopes: string[] | string): string {
return Array.isArray(scopes) ? scopes.join(' ') : toString(scopes);
}
/**
* Create basic auth header.
*/