-
Notifications
You must be signed in to change notification settings - Fork 114
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
[extension] Use dedicated audience for dust api. Add scopes verification #8719
Conversation
|
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.
LGTM, left one last comment.
front/lib/api/auth0.ts
Outdated
requiredScopes?: Record<string, string> | ||
) { | ||
if (requiredScopes && req.method && requiredScopes[req.method]) { | ||
return [requiredScopes[req.method]]; |
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.
Why do we need to return an array here? If it's expected maybe it should be getRequiredScopes
and let's define the return type.
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.
Note: are they all required ?
Usually it's one of them, not all of them as scopes are granular.
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.
If one of them, i would rename as getAllowedScopes()
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.
right, I don't think we need an array for now
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.
i was expecting all required, but yes could be an array of "at least one", that's probably more useful. For now i think we can stick with one single value
Love that ! |
|
@tdraier but I'm wondering if you are not going to break the raycast extension. |
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.
I'm putting a request change because I'm worried that it breaks the raycast extension.
Let's talk before merging.
front/lib/api/auth0.ts
Outdated
return resolve(new Err(Error("Invalid token payload."))); | ||
} | ||
|
||
if (requiredScopes) { |
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.
don't you need to check if the audience matches too ?
(and maybe skip the checks if not the right audience, as a temporary measure not to break the raycast extension)
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.
The audience is checked along with the expiration and issuer by jwt.verify
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.
I believe it's checked for consistency / signature but not for a specific value (may be wrong)
My point here is twofold:
- do the checks on scope only if the audience match the expected audience
- TEMPORARY, otherwise, let it go thru (so the raycast extension still works)
After the extension is updated, we'll wait a few days and then remove the temporary passthru.
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.
( jwt.verify checks that the audience matches the one passed in parameter )
front/lib/api/auth0.ts
Outdated
|
||
export function getRequiredScope( | ||
req: NextApiRequest, | ||
requiredScopes?: Record<string, string> |
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.
imho, the typing of that arg should be more strict (POST|GET|PATCH|DELETE: scopes that exists)
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.
req.method is not typed (it's a string), so in theory I can receive anything in here
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.
...but in practice we know what we use (and we can extends if needed)
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.
i was afraid of the typings, but ok, done 😛
front/lib/api/auth0.ts
Outdated
if (requiredScopes) { | ||
const availableScopes = decoded.scope.split(" "); | ||
if ( | ||
requiredScopes.some((scope) => !availableScopes.includes(scope)) |
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.
see my comment required vs allowed.
this definitely require changes in raycast extension |
I can do it swiftly but there is a delay for them to approve, and for users to update. We need an intermediary step where the extension still work. |
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.
LGTM !
Description
This introduces the usage of a custom auth0 API for our public api. The audience is set in an env var ,
DUST_API_AUDIENCE
which should behttps://dust-dev.tt/api/v1
in development orhttps://dust.tt/api/v1
in production.This API defines scopes in auth0 configuration, that will need to be extended, for checking particular endpoints in the api. All scopes used by the app are set - we'll have to add/define other ones in another PR.
The scopes required by the app must be specified when requesting authorization, which will result in displaying a consent screen :
(This consent screen can be skipped for 1st party apps , i.e. our own apps registered in our auth0 tenant, but must be shown for 3rd party apps)
The 2 wrappers
withPublicAPIAuthentication
andwithAuth0TokenAuthentication
are extended to support new option "resourceName" that can be used to create the scope.Scope are only checked against oauth tokens .
sk-
keys are considered system and do not include any scope (no scope check).Risk
For oauth users, some routes now require scope.
Deploy Plan
DUST_API_AUDIENCE
env vars