File size: 1,164 Bytes
07af8f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { OAuthServerConfig } from '../types/index.js';

export const DEFAULT_OAUTH_SERVER_CONFIG: OAuthServerConfig = {
  enabled: true,
  accessTokenLifetime: 3600,
  refreshTokenLifetime: 1209600,
  authorizationCodeLifetime: 300,
  requireClientSecret: false,
  allowedScopes: ['read', 'write'],
  requireState: false,
  dynamicRegistration: {
    enabled: true,
    allowedGrantTypes: ['authorization_code', 'refresh_token'],
    requiresAuthentication: false,
  },
};

export const cloneDefaultOAuthServerConfig = (): OAuthServerConfig => {
  const allowedScopes = DEFAULT_OAUTH_SERVER_CONFIG.allowedScopes
    ? [...DEFAULT_OAUTH_SERVER_CONFIG.allowedScopes]
    : [];

  const baseDynamicRegistration =
    DEFAULT_OAUTH_SERVER_CONFIG.dynamicRegistration ?? {
      enabled: false,
      allowedGrantTypes: [],
      requiresAuthentication: false,
    };

  const dynamicRegistration = {
    ...baseDynamicRegistration,
    allowedGrantTypes: baseDynamicRegistration.allowedGrantTypes
      ? [...baseDynamicRegistration.allowedGrantTypes]
      : [],
  };

  return {
    ...DEFAULT_OAUTH_SERVER_CONFIG,
    allowedScopes,
    dynamicRegistration,
  };
};