All files / src/oauth oauth-app.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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          233x 233x                                 233x 150x              
/**
 * GitLab OAuth application a sign-in runs against: the instance and the application
 * registered on it. Every GitLab OAuth call of one account uses the same application.
 */
 
import { GITLAB_BASE_URL } from '../config';
import { normalizeInstanceUrl } from '../utils/url';
import type { OAuthConfig } from './config';
 
export interface GitLabOAuthApp {
  /** Instance base URL, normalized; may include a base path. */
  baseUrl: string;
  /** Human-readable instance label, when configured. */
  label?: string;
  /** OAuth application ID on that instance. */
  clientId: string;
  /** Secret, only for confidential applications. */
  clientSecret?: string;
  /** Scopes requested from GitLab (comma or space separated). */
  scopes: string;
}
 
/** Application from OAUTH_CLIENT_ID on GITLAB_API_URL, used when no instance was chosen. */
export function defaultOAuthApp(config: OAuthConfig): GitLabOAuthApp {
  return {
    baseUrl: normalizeInstanceUrl(GITLAB_BASE_URL),
    clientId: config.gitlabClientId,
    clientSecret: config.gitlabClientSecret,
    scopes: config.gitlabScopes,
  };
}