Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support org auth tokens in old wizards #409

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ brew update
brew install getsentry/tools/sentry-wizard
```

- fix: Support org auth tokens in old wizards (#409)

## 3.10.0

- feat(remix): Add Remix wizard (#387)
Expand Down
47 changes: 46 additions & 1 deletion lib/Steps/PromptForParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@ export class PromptForParameters extends BaseStep {
}

private _validateAuthToken(input: string): boolean | string {
if (!input.match(/[0-9a-f]{64}/g)) {
const isOrgToken = input.startsWith('sntrys_');

if (isOrgToken) {
if (!isValidOrgToken(input)) {
return 'Make sure you correctly copied your auth token. It should start with "sntrys_"';
}
return true;
}

if (!input.match(/(sntrys_)?[0-9a-f]{64}/g)) {
return 'Make sure you copied the correct auth token, it should be 64 hex chars';
}
return true;
Expand Down Expand Up @@ -149,3 +158,39 @@ export class PromptForParameters extends BaseStep {
return true;
}
}

type MaybeOrgAuthToken = {
iat?: number;
url?: string;
org?: string;
region_url?: string;
};

/**
* Trying to parse and decode an org auth token. Based on:
* - https://github.com/getsentry/rfcs/blob/main/text/0091-ci-upload-tokens.md#parsing-tokens
* - https://github.com/getsentry/rfcs/blob/main/text/0091-ci-upload-tokens.md#token-facts
*/
function isValidOrgToken(input: string): boolean {
if (!input.startsWith('sntrys_')) {
return false;
}

const tokenParts = input.split('_');
if (tokenParts.length < 3) {
return false;
}

try {
const payload = tokenParts[1];
const decodedPayload = Buffer.from(payload, 'base64').toString();
const jsonPayload = JSON.parse(decodedPayload) as MaybeOrgAuthToken;
if (!jsonPayload.iat || !jsonPayload.url || !jsonPayload.org) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will iat and url always be there? Could they be null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, they should, spec wise. we seem to have an issue where url is sometimes empty when running this locally, but this is something that we have to fix backend-side (and should not affect sentry.io)

return false;
}
} catch {
return false;
}

return true;
}