-
Notifications
You must be signed in to change notification settings - Fork 0
feature: more flexible token payload and authorization function #1
Copy link
Copy link
Open
Description
📄 Summary
Now module has no flexibilty, no ability to change token payload, no flexibilty with AuthFunc:
// Authoorize func is a function/method that Auth recieves as a dependency
// Auth will use to login users on Auth.LoginHandler
type AuthorizeFunc func(username, password string) (user_id int, err error)🧩 Problem / Motivation
module like this need more flexibilty, to make it easier to connect to already working project, without, or with a little bit of changes
💡 Proposed Solution
i would still work with some AuthFunc, but its signature will be like func(any) (Payload, error)
And auth module structure will be a genereric. structure
type Auth[Payload any] struct The type Payload should be, what AuthFunc returns, and what hooks ( that user can specify in the config ) will return
hook signature should be: func(Payload)
What about inside of the module?
It is more complicated, but i have a solution.
First, what is the problem with Payload generic:
- we need to save user's Payload structure
- serialize to json user's structure, when creating a token
- add to jwt token payload an ExpireTime field
- store refresh tokens, but we need to connect refresh toklens to user, beacuse module in future need to give api to revoke all tokens from user ( log out on all devices )
Second, what is the problem with any parameter in AuthFunc:
- this is, what
AuthFunctakes to authorize the user, so DTO ( json that nodule recieves on login handler ) should copy its structure
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels