cmd-johnson / deno-oauth2-client

Minimalistic OAuth 2.0 client for Deno.
MIT License
45 stars 9 forks source link

Using this with Auth0 #33

Closed adoublef closed 1 year ago

adoublef commented 1 year ago

I am looking to use this alongside auth0 and I wanted to know how I would go about including the audience when crafting the url? I can see that there are additional options here

// extracted from my application
    return new OAuth2Client({
        defaults: {
            requestOptions: {
                urlParams: {
                    audience: Deno.env.get("AUTH0_AUDIENCE")!,
                },
            },

However this doesn't seem to be used within the code.getAuthorizationUri method and wondering what is the recommended way of setting this up. The audience is required to get a valid JWT back from their services (without the audience the payload is missing)

cmd-johnson commented 1 year ago

The requestOptions object is only considered for requests made by the oauth2 client itself (e.g. token requests, ...)

Since you have to redirect the user agent to the authorization URI instead of directly calling it yourself, the getAuthorizationUri returns an object including the uri value. If you want to add additional search parameters (like audience), you can just modify that value like this:

const { uri } = await client.code.getAuthorizationUri({ /* ... */ });
uri.searchParams.set("audience", Deno.env.get("AUTH0_AUDIENCE"));
return uri; // the authorization URI including the "audience" search parameter
adoublef commented 1 year ago

ah thank you for the clarity, I can pass this along to the other maintainer as seems this could be incorporated into their package easily

cmd-johnson commented 1 year ago

Seeing that denoland/deno_kv_oauth/issues/140 was closed, I'll close this issue here as well :slightly_smiling_face: