Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
2cdb6c0a
Commit
2cdb6c0a
authored
Oct 20, 2015
by
Joe Bowers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user: more convenient way to read claims that have already been validated
parent
792b72ef
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
29 deletions
+43
-29
email_verification.go
user/email_verification.go
+3
-20
invitation.go
user/invitation.go
+21
-0
password.go
user/password.go
+2
-9
user.go
user/user.go
+17
-0
No files found.
user/email_verification.go
View file @
2cdb6c0a
...
...
@@ -65,30 +65,13 @@ func ParseAndVerifyEmailVerificationToken(token string, issuer url.URL, keys []k
}
func
(
e
EmailVerification
)
UserID
()
string
{
uid
,
ok
,
err
:=
e
.
Claims
.
StringClaim
(
"sub"
)
if
!
ok
||
err
!=
nil
{
panic
(
"EmailVerification: no sub claim. This should be impossible."
)
}
return
uid
return
assertStringClaim
(
e
.
Claims
,
"sub"
)
}
func
(
e
EmailVerification
)
Email
()
string
{
email
,
ok
,
err
:=
e
.
Claims
.
StringClaim
(
ClaimEmailVerificationEmail
)
if
!
ok
||
err
!=
nil
{
panic
(
"EmailVerification: no email claim. This should be impossible."
)
}
return
email
return
assertStringClaim
(
e
.
Claims
,
ClaimEmailVerificationEmail
)
}
func
(
e
EmailVerification
)
Callback
()
*
url
.
URL
{
cb
,
ok
,
err
:=
e
.
Claims
.
StringClaim
(
ClaimEmailVerificationCallback
)
if
!
ok
||
err
!=
nil
{
panic
(
"EmailVerification: no callback claim. This should be impossible."
)
}
cbURL
,
err
:=
url
.
Parse
(
cb
)
if
err
!=
nil
{
panic
(
"EmailVerificaiton: can't parse callback. This should be impossible."
)
}
return
cbURL
return
assertURLClaim
(
e
.
Claims
,
ClaimEmailVerificationCallback
)
}
user/invitation.go
View file @
2cdb6c0a
...
...
@@ -57,3 +57,24 @@ func ParseAndVerifyInvitationToken(token string, issuer url.URL, keys []key.Publ
return
Invitation
{
tokenClaims
.
Claims
},
nil
}
func
(
iv
Invitation
)
UserID
()
string
{
return
assertStringClaim
(
iv
.
Claims
,
"sub"
)
}
func
(
iv
Invitation
)
Password
()
Password
{
pw
:=
assertStringClaim
(
iv
.
Claims
,
ClaimPasswordResetPassword
)
return
Password
(
pw
)
}
func
(
iv
Invitation
)
Email
()
string
{
return
assertStringClaim
(
iv
.
Claims
,
ClaimEmailVerificationEmail
)
}
func
(
iv
Invitation
)
ClientID
()
string
{
return
assertStringClaim
(
iv
.
Claims
,
"aud"
)
}
func
(
iv
Invitation
)
Callback
()
*
url
.
URL
{
return
assertURLClaim
(
iv
.
Claims
,
ClaimInvitationCallback
)
}
user/password.go
View file @
2cdb6c0a
...
...
@@ -257,18 +257,11 @@ func ParseAndVerifyPasswordResetToken(token string, issuer url.URL, keys []key.P
}
func
(
e
PasswordReset
)
UserID
()
string
{
uid
,
ok
,
err
:=
e
.
Claims
.
StringClaim
(
"sub"
)
if
!
ok
||
err
!=
nil
{
panic
(
"PasswordReset: no sub claim. This should be impossible."
)
}
return
uid
return
assertStringClaim
(
e
.
Claims
,
"sub"
)
}
func
(
e
PasswordReset
)
Password
()
Password
{
pw
,
ok
,
err
:=
e
.
Claims
.
StringClaim
(
ClaimPasswordResetPassword
)
if
!
ok
||
err
!=
nil
{
panic
(
"PasswordReset: no password claim. This should be impossible."
)
}
pw
:=
assertStringClaim
(
e
.
Claims
,
ClaimPasswordResetPassword
)
return
Password
(
pw
)
}
...
...
user/user.go
View file @
2cdb6c0a
...
...
@@ -42,6 +42,23 @@ const (
ClaimInvitationCallback
=
"http://coreos.com/invitation/callback"
)
func
assertStringClaim
(
claims
jose
.
Claims
,
k
string
)
string
{
s
,
ok
,
err
:=
claims
.
StringClaim
(
k
)
if
!
ok
||
err
!=
nil
{
panic
(
"claims were not validated correctly"
)
}
return
s
}
func
assertURLClaim
(
claims
jose
.
Claims
,
k
string
)
*
url
.
URL
{
ustring
:=
assertStringClaim
(
claims
,
k
)
ret
,
err
:=
url
.
Parse
(
ustring
)
if
err
!=
nil
{
panic
(
"url claim was not validated correctly"
)
}
return
ret
}
type
UserIDGenerator
func
()
(
string
,
error
)
func
DefaultUserIDGenerator
()
(
string
,
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment