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

feat: modify auth token url based on instance param #260

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cmars
Copy link
Contributor

@cmars cmars commented Oct 9, 2024

If an instance parameter is provided in the redirect, use it to modify
the URL from where the oauth token is obtained.

The instance provided is the Snyk region domain, minus the api. host
prefix.

Stacked on #258

Snyk's OAuth implementation is capable of indicating the environment
which the user is authenticated into and authorized to access.

This is specified in the audience JWT claim ("aud"). Snyk's
implementation of this claim contains an array of strings, per RFC 7519.

If set and non-empty, the first audience URL is taken as the default API
URL that the client should use, unless the endpoint was specifically
configured.
It's a test JWT created on jwt.io for testing the parsing of claims
and cannot be used as a valid authorization anywhere.
@cmars cmars force-pushed the feat/redirect-with-instance-param branch 3 times, most recently from 6788c04 to 26d7b95 Compare October 9, 2024 21:39
If an instance parameter is provided in the redirect, use it to modify
the URL from where the oauth token is obtained.

The instance provided is the Snyk region domain, minus the api. host
prefix.
@cmars cmars force-pushed the feat/redirect-with-instance-param branch from 26d7b95 to 345bc9e Compare October 9, 2024 21:42
return fmt.Sprintf("api.%s", instance)
}

var redirectAuthHostRE = regexp.MustCompile(`^api\.(.+)\.snyk\.io$`)

Choose a reason for hiding this comment

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

snykgov too!

return "", err
}
if len(c.Aud) > 0 {
return c.Aud[0], nil
Copy link
Contributor

Choose a reason for hiding this comment

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

could we by any change have multiple entries in the aud claim ?

Copy link
Member

Choose a reason for hiding this comment

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

From the spec:

In the general case, the "aud" value is an array of case-
sensitive strings, each containing a StringOrURI value. In the
special case when the JWT has one audience, the "aud" value MAY be a
single case-sensitive string containing a StringOrURI value. The
interpretation of audience values is generally application specific.
Use of this claim is OPTIONAL.
https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3

It is almost expected for there to be multiple values available. We should likely search the list and extract the first one which meets our criteria.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Guidance from the IdP team is to use the first value. I can provide more context offline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants