Skip to content

Commit

Permalink
Add docs around bespoke OAuth solution
Browse files Browse the repository at this point in the history
  • Loading branch information
cmackenzie1 committed Dec 18, 2024
1 parent 11006c0 commit 08b2507
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/wrangler/src/pipelines/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,25 @@ interface S3AccessKey {
secretAccessKey: string;
}

// Generate a Service Token to write to R2 for a pipeline
/**
* Generate an R2 service token for the given account ID, bucket name, and pipeline name.
*
* This function kicks off its own OAuth process using the Workers Pipelines OAuth client requesting the scope
* `pipelines:setup`. Once the user confirms, our OAuth callback endpoint will validate the request, exchange the
* authorization code and return a bucket-scoped R2 token.
*
* This OAuth flow is distinct from the one used in `wrangler login` to ensure these tokens are generated server-side
* and that only the tokens of concern are returned to the user.
* @param accountId
* @param bucketName
* @param pipelineName
*/
export async function generateR2ServiceToken(
accountId: string,
bucketName: string,
pipelineName: string
): Promise<S3AccessKey> {
// TODO: Refactor into startHttpServerWithTimeout function and update `getOauthToken`
let server: http.Server;
let loginTimeoutHandle: ReturnType<typeof setTimeout>;
const timerPromise = new Promise<S3AccessKey>((_, reject) => {
Expand Down

0 comments on commit 08b2507

Please sign in to comment.