mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 13:29:02 +08:00
feat(core): improve auth handling (#15271)
fix #15270 fix #15260 fix #15257 #### PR Dependency Tree * **PR #15271** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal)
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
InvalidOauthResponse,
|
||||
OnEvent,
|
||||
safeFetch,
|
||||
type SafeFetchOptions,
|
||||
} from '../../../base';
|
||||
import { OAuthProviderName } from '../config';
|
||||
import { OAuthProviderFactory } from '../factory';
|
||||
@@ -79,6 +80,15 @@ export abstract class OAuthProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected fetchOptions(_url: string | URL): SafeFetchOptions {
|
||||
return {
|
||||
timeoutMs: 10_000,
|
||||
maxRedirects: 3,
|
||||
maxBytes: 1024 * 1024,
|
||||
allowedHeaders: ['authorization', 'content-type', 'accept'],
|
||||
};
|
||||
}
|
||||
|
||||
protected async fetchJson<T>(
|
||||
url: string,
|
||||
init?: RequestInit,
|
||||
@@ -87,12 +97,7 @@ export abstract class OAuthProvider {
|
||||
const response = await safeFetch(
|
||||
url,
|
||||
{ ...init, headers: { ...init?.headers, Accept: 'application/json' } },
|
||||
{
|
||||
timeoutMs: 10_000,
|
||||
maxRedirects: 3,
|
||||
maxBytes: 1024 * 1024,
|
||||
allowedHeaders: ['authorization', 'content-type', 'accept'],
|
||||
}
|
||||
this.fetchOptions(url)
|
||||
);
|
||||
|
||||
const body = await response.text();
|
||||
|
||||
Reference in New Issue
Block a user