Skip to content

Conversation

@klaidliadon
Copy link
Contributor

@klaidliadon klaidliadon commented Nov 14, 2024

Split session and verify middleware.

JWT Auth is created by an interface, which has two implementations:

  • Static: replaces the existing fixed secret
  • Project dependent: allows to return a different JWT Auth depending on the Project.

Copy link
Contributor

@david-littlefarmer david-littlefarmer left a comment

Choose a reason for hiding this comment

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

Do i understand it right, that on every request we create new JWT verifier and check the token against it?

If so, then why not to predefine them for exmaple in array and just try to iterate through them, until the one of them is successful since the private and/or public keys are defined on startup of server.

Also can you please describe some simple flow of verifier? I find it confusing.

Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

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

Great, this is getting better!

}

func Session(cfg Options) func(next http.Handler) http.Handler {
func VerifyToken(cfg Options) func(next http.Handler) http.Handler {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we could split Options struct into two types -- one for Verifier and one for Sessions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Imho, this middleware needs nothing but JWTSecret and ErrHandler. It should always verify HS256 JWT from both Authorization header and Cookie.

I don't see the need for AuthProvider interface. Is it useful for anything else? I think it just locks us down to this implementation -- switching algorithms, jwks or supporting secret rotation or multiple algorithms would be more difficult.

Copy link
Contributor

Choose a reason for hiding this comment

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

Imho, stack/api's ProjectJWTVerifier should be a a separate implementation that doesn't have anything in common with this Verifier except for passing the token into context via ctx = jwtauth.NewContext(ctx, token, nil)

}
}

func Session(cfg Options) func(next http.Handler) http.Handler {
Copy link
Contributor

Choose a reason for hiding this comment

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

Session needs ErrorHandler, UserStore and a way to fetch AccessKey.

webrpc = v1

name = access-control
name = auth-control
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name = auth-control
name = authcontrol

VojtechVitek
VojtechVitek previously approved these changes Nov 19, 2024
@klaidliadon klaidliadon merged commit e9b255d into master Nov 19, 2024
2 checks passed
@klaidliadon klaidliadon deleted the split-session branch November 19, 2024 12:06
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.

4 participants