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

Role based user session #39

Open
akelyasir opened this issue May 29, 2023 · 3 comments
Open

Role based user session #39

akelyasir opened this issue May 29, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@akelyasir
Copy link

Hi,

Will you set an example for a role-based user session? With the cache system. Do we need to develop the project ourselves?

Good work and good luck.

@photino
Copy link
Collaborator

photino commented May 29, 2023

We support extracting a SessionId from the session-id header. The format is defined in W3C's Session Identification URI. We will provide an example for that.

@photino photino added the enhancement New feature or request label May 29, 2023
@akelyasir
Copy link
Author

I've seen SessionId , but I couldn't figure out how to advance your use case here. I could not understand whether you will use a different method according to the access_key value in the user model or with the password. Also, like, are you going to create a rule according to the role structure in the user model. I am impatiently waiting for your update.

@photino
Copy link
Collaborator

photino commented May 30, 2023

The SessionId can be used in the following way:

// 1. Generates an `AccessKeyId`.
let key = AccessKeyId::new();

// 2. Generates a `SessionId`.
let session_id = SessionId::new::<Sha256>("your.app.com", key);

// 3. Records a map of the `SessionId` and `AccessKeyId` using a cache system.
let mut map = HashMap::new();
map.insert(session_id, key);

// 4. Extracts a `SessionId` from the request.
let session_id = req.parse_session_id().unwrap();

// 5. Gets the corresponding `AccessKey` from the cache system.
let key = map.get(session_id).unwrap();

// 6. Validates the `SessionId`.
let is_valid = session_id.validate_with::<Sha256>("your.app.com", key);

If the AccessKeyId is bound to a user, then a SessionId can be used to identify a user. But we think that SessionId and AccessKeyId can be used in a more general sense (they can also be bound to a group).

The zino-model is totally optional. It provides some models for prototyping and testing. The role structure in the user model does not have a close relation to SessionId (Of course, we can also bind an AccessKeyId to a specific role).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants