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

Add support for session authentication #935

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft

Conversation

ezekg
Copy link
Member

@ezekg ezekg commented Feb 24, 2025

Groundwork for #409 and Portal.

@ezekg ezekg force-pushed the feature/sessions branch 5 times, most recently from db47748 to 8c1314a Compare February 24, 2025 18:04
@ezekg ezekg mentioned this pull request Feb 24, 2025
8 tasks
@ezekg ezekg force-pushed the feature/sessions branch 15 times, most recently from 06bba15 to c7b1233 Compare February 24, 2025 21:30
if token.save
cookies.encrypted[:session_id] = { value: session.id, httponly: true, secure: true, same_site: :none, expires: session.expiry, domain: Keygen::DOMAIN }
Copy link
Member Author

@ezekg ezekg Feb 24, 2025

Choose a reason for hiding this comment

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

What if we're generating a token on behalf of another object, but don't want to clobber our session? e.g. an admin generating an environment token for an integration. I guess use the object's tokens relationship instead of the root? i.e. POST /v1/environments/<environment>/tokens instead of /v1/tokens?

Copy link
Member Author

@ezekg ezekg Feb 24, 2025

Choose a reason for hiding this comment

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

Or we could start a session only for :password authn?

include Environmental
include Accountable

belongs_to :token
Copy link
Member Author

Choose a reason for hiding this comment

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

How will this work with SSO, i.e. not tied to a token? Maybe the token association should be optional?

Copy link
Member Author

@ezekg ezekg Feb 26, 2025

Choose a reason for hiding this comment

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

But then we'd need to expose a sessions resource so that they can be revoked.

May be easier to simply generate a token as part of the SSO flow.

@ezekg ezekg force-pushed the feature/sessions branch 3 times, most recently from c292f5a to 79995e3 Compare February 26, 2025 17:19
@@ -139,6 +154,11 @@ def revoke
resource: token,
)

# expire session if we're revoking the current token
if token == current_token
cookies.delete(:session_id, domain: Keygen::DOMAIN, same_site: :none)
Copy link
Member Author

@ezekg ezekg Feb 26, 2025

Choose a reason for hiding this comment

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

Is all this really needed? Invalid sessions will be auto-expired after unsuccessful authn.

@@ -127,6 +137,11 @@ def regenerate
resource: token,
)

# expire session if we're regenerating the current token
if token == current_token
cookies.delete(:session_id, domain: Keygen::DOMAIN, same_site: :none)
Copy link
Member Author

@ezekg ezekg Feb 26, 2025

Choose a reason for hiding this comment

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

Do we really want to expire the current session when a token is regenerated?

Using token.regenerate!(except: Current.session) may be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

Or should we revoke all sessions and generate a new session entirely? I lean towards that.

Copy link
Member Author

Choose a reason for hiding this comment

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

regenerate! can return the new session.

@ezekg ezekg force-pushed the feature/sessions branch 2 times, most recently from 2710894 to 311cc7e Compare February 27, 2025 00:16
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.

1 participant