-
Notifications
You must be signed in to change notification settings - Fork 9
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
base: main
Are you sure you want to change the base?
Conversation
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.
6788c04
to
26d7b95
Compare
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.
26d7b95
to
345bc9e
Compare
return fmt.Sprintf("api.%s", instance) | ||
} | ||
|
||
var redirectAuthHostRE = regexp.MustCompile(`^api\.(.+)\.snyk\.io$`) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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