0
Get OpenID configuration for OIDC in Pipelines
One script reply has been approved by the moderators Verified
Created by hugo697 425 days ago Viewed 9143 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 425 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Get OpenID configuration for OIDC in Pipelines
7
 * This is part of OpenID Connect for Pipelines, see https://support.atlassian.com/bitbucket-cloud/docs/integrate-pipelines-with-resource-servers-using-oidc/
8
 */
9
export async function main(auth: Bitbucket, workspace: string) {
10
  const url = new URL(
11
    `https://api.bitbucket.org/2.0/workspaces/${workspace}/pipelines-config/identity/oidc/.well-known/openid-configuration`
12
  );
13

14
  const response = await fetch(url, {
15
    method: "GET",
16
    headers: {
17
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
18
    },
19
    body: undefined,
20
  });
21
  if (!response.ok) {
22
    const text = await response.text();
23
    throw new Error(`${response.status} ${text}`);
24
  }
25
  return await response.text();
26
}
27