Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Vaultwarden
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Vaultwarden
Commits
680f5e83
Unverified
Commit
680f5e83
authored
6 years ago
by
Nick Fox
Browse files
Options
Downloads
Patches
Plain Diff
Add Invite JWT struct and supporting functions
parent
d3e4fb88
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/auth.rs
+35
-0
35 additions, 0 deletions
src/auth.rs
with
35 additions
and
0 deletions
src/auth.rs
+
35
−
0
View file @
680f5e83
...
@@ -56,6 +56,27 @@ pub fn decode_jwt(token: &str) -> Result<JWTClaims, String> {
...
@@ -56,6 +56,27 @@ pub fn decode_jwt(token: &str) -> Result<JWTClaims, String> {
}
}
}
}
pub
fn
decode_invite_jwt
(
token
:
&
str
)
->
Result
<
InviteJWTClaims
,
String
>
{
let
validation
=
jsonwebtoken
::
Validation
{
leeway
:
30
,
// 30 seconds
validate_exp
:
true
,
validate_iat
:
false
,
// IssuedAt is the same as NotBefore
validate_nbf
:
true
,
aud
:
None
,
iss
:
Some
(
JWT_ISSUER
.clone
()),
sub
:
None
,
algorithms
:
vec!
[
JWT_ALGORITHM
],
};
match
jsonwebtoken
::
decode
(
token
,
&
PUBLIC_RSA_KEY
,
&
validation
)
{
Ok
(
decoded
)
=>
Ok
(
decoded
.claims
),
Err
(
msg
)
=>
{
error!
(
"Error validating jwt - {:#?}"
,
msg
);
Err
(
msg
.to_string
())
}
}
}
#[derive(Debug,
Serialize,
Deserialize)]
#[derive(Debug,
Serialize,
Deserialize)]
pub
struct
JWTClaims
{
pub
struct
JWTClaims
{
// Not before
// Not before
...
@@ -87,6 +108,20 @@ pub struct JWTClaims {
...
@@ -87,6 +108,20 @@ pub struct JWTClaims {
pub
amr
:
Vec
<
String
>
,
pub
amr
:
Vec
<
String
>
,
}
}
#[derive(Debug,
Serialize,
Deserialize)]
pub
struct
InviteJWTClaims
{
// Not before
pub
nbf
:
i64
,
// Expiration time
pub
exp
:
i64
,
// Issuer
pub
iss
:
String
,
// Subject
pub
sub
:
String
,
pub
email
:
String
,
}
///
///
/// Bearer token authentication
/// Bearer token authentication
///
///
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment