-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In some cases access to the standard claim's aud can be useful for consumer. For example to reject tokens made for different, but allowed aud passed verification just fine. However, the full claim is not avail, just User part of it. The change sets Audience field from std claim aud. In other words the goal is to prevent valid token issued for subsystem A to be used in subsystem B. The package doesn't provide such a rejection but allow user to handle it on application level.
- Loading branch information
Showing
4 changed files
with
16 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,9 @@ func TestAuthJWTCookie(t *testing.T) { | |
handler := func(w http.ResponseWriter, r *http.Request) { | ||
u, err := token.GetUserInfo(r) | ||
assert.NoError(t, err) | ||
assert.Equal(t, token.User{Name: "name1", ID: "id1", Picture: "http://example.com/pic.png", IP: "127.0.0.1", Email: "[email protected]", Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, u) | ||
assert.Equal(t, token.User{Name: "name1", ID: "id1", Picture: "http://example.com/pic.png", | ||
IP: "127.0.0.1", Email: "[email protected]", Audience: "test_sys", | ||
Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, u) | ||
w.WriteHeader(201) | ||
} | ||
mux.Handle("/auth", a.Auth(http.HandlerFunc(handler))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,7 +264,8 @@ func TestJWT_GetFromHeader(t *testing.T) { | |
assert.Equal(t, testJwtValid, token) | ||
assert.False(t, j.IsExpired(claims)) | ||
assert.Equal(t, &User{Name: "name1", ID: "id1", Picture: "http://example.com/pic.png", IP: "127.0.0.1", | ||
Email: "[email protected]", Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, claims.User) | ||
Email: "[email protected]", Audience: "test_sys", | ||
Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, claims.User) | ||
assert.Equal(t, "remark42", claims.Issuer) | ||
|
||
req = httptest.NewRequest("GET", "/", nil) | ||
|
@@ -295,7 +296,8 @@ func TestJWT_GetFromQuery(t *testing.T) { | |
assert.Equal(t, testJwtValid, token) | ||
assert.False(t, j.IsExpired(claims)) | ||
assert.Equal(t, &User{Name: "name1", ID: "id1", Picture: "http://example.com/pic.png", IP: "127.0.0.1", | ||
Email: "[email protected]", Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, claims.User) | ||
Email: "[email protected]", Audience: "test_sys", | ||
Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, claims.User) | ||
assert.Equal(t, "remark42", claims.Issuer) | ||
|
||
req = httptest.NewRequest("GET", "/blah?token="+testJwtExpired, nil) | ||
|
@@ -349,7 +351,8 @@ func TestJWT_SetAndGetWithCookies(t *testing.T) { | |
r, _, err := j.Get(req) | ||
assert.Nil(t, err) | ||
assert.Equal(t, &User{Name: "name1", ID: "id1", Picture: "http://example.com/pic.png", IP: "127.0.0.1", | ||
Email: "[email protected]", Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, r.User) | ||
Email: "[email protected]", Audience: "test_sys", | ||
Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, r.User) | ||
assert.Equal(t, "remark42", claims.Issuer) | ||
assert.Equal(t, true, claims.SessionOnly) | ||
t.Log(resp.Cookies()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters