-
Notifications
You must be signed in to change notification settings - Fork 24
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
Allow custom callback_url #53
Conversation
Hey @kengreeff thanks so much for the PR. Love your work but I do have one concern from a security perspective about passing the redirect url as part of the query string. Essentially I could share a link I have a couple of ideas on how we could achieve this securely and would love your thoughts:
|
@DaveOrDead Yea, good thinking - realistically it is always a path, not a full url - I just copied the naming convention from next auth. Let's roll with Do you want to use |
Would |
@kengreeff ah I wasn't clear enough in what I meant by saying:
that was to address this use case:
If we set a convention for the cookie name, for example After the user authenticates on Kinde they are redirected to your app and the middleware reads that cookie and puts them back on the page they were on. This means that for the Pages use case, nothing needs to be set by the developer as it is just handled by default by the middleware, but in the case of actions such as "like" you could opt in to setting a cookie. Otherwise the developer would have to manipulate the login/register url in the case of both page restriction and actions restriction. |
@DaveOrDead that seems like it might be quite a bit of work when compared to a callback path in the query string. This is an example of what we do now: <Button
as={isAuthenticated ? 'button' : 'a'}
colorScheme={userPostLikesCount ? 'red' : 'gray'}
leftIcon={userPostLikesCount ? <HiHeart fontSize={24} /> : <HiOutlineHeart fontSize={24} />}
href={isAuthenticated
? undefined
: `/users/login?redirect=${redirect || `/${post?.id}`}`}
onClick={userPostLikesCount
? () => deletePostLikeFn({
id: post?.id,
})
: () => createPostLikeFn({
id: post?.id,
})}
size="md"
>
{postLikesCount} {postLikesCount === 1 ? 'Like' : 'Likes'}
</Button> I feel like the cookie route would add a lot more code for the developer. Could you possibly show me what your implementation would look like in this code block? |
looks like nextauth handles redirects like this:
Seems like a simple way to prevent dodgy redirects - thoughts? |
@kengreeff looks good to me |
@@ -7,7 +7,12 @@ const initialState = { | |||
const SESSION_PREFIX = 'pkce-verifier'; | |||
|
|||
const KINDE_SITE_URL = process.env.KINDE_SITE_URL; | |||
const KINDE_AUTH_API_PATH = process.env.KINDE_AUTH_API_PATH || '/api/auth'; | |||
|
|||
// We need to use NEXT_PUBLIC for frontend vars |
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.
this was a real gotcha in dev!
@DaveOrDead ready for you mate - I have also removed some unused code from files where I found it to clean up. I have left as I tested the old code and could be redirected to google, the new code prevents this. |
@@ -7,6 +7,7 @@ | |||
"typings": "index.d.ts", | |||
"scripts": { | |||
"build": "genversion --es6 src/utils/version.js && rollup -c", | |||
"build:watch": "genversion --es6 src/utils/version.js && rollup -c -w", |
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.
Added this to make dev a bit easier yarn build:watch
src/handlers/pageRouter/callback.js
Outdated
if (options?.callback_url) { | ||
redirectUrl = sanitizeRedirect({ | ||
baseUrl: new URL(config.redirectURL).origin, | ||
url: options.callback_url |
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.
@kengreeff all looks awesome. The only thing I'd say it I'm not sure on calling the option callback_url
just because it has a specific meaning in oauth flows that it is the url being called back to after authentication to complete the flow. Whereas this is specifically the url to pass onto post-authenticating and after the callback has completed.
Maybe next_url
?
What are your thoughts @peterphanouvong ?
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.
How about redirect_url
?
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.
Thank for the PR 🚀
Allow custom callback_url
Explain your changes
Hey team, I have added the ability to store the options object in the verifier cookie so that once verified we can check if the
callback_url
has been set and redirect there instead of the defaults.Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.