-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use struct types for claim related types (#283)
* oidc: add regression tests for token claim json this helps to verify that the same JSON is produced, after these types are refactored. * refactor: use struct types for claim related types BREAKING CHANGE: The following types are changed from interface to struct type: - AccessTokenClaims - IDTokenClaims - IntrospectionResponse - UserInfo and related types. The following methods of OPStorage now take a pointer to a struct type, instead of an interface: - SetUserinfoFromScopes - SetUserinfoFromToken - SetIntrospectionFromToken The following functions are now generic, so that type-safe extension of Claims is now possible: - op.VerifyIDTokenHint - op.VerifyAccessToken - rp.VerifyTokens - rp.VerifyIDToken - Changed UserInfoAddress to pointer in UserInfo and IntrospectionResponse. This was needed to make omitempty work correctly. - Copy or merge maps in IntrospectionResponse and SetUserInfo * op: add example for VerifyAccessToken * fix: rp: wrong assignment in WithIssuedAtMaxAge WithIssuedAtMaxAge assigned its value to v.maxAge, which was wrong. This change fixes that by assiging the duration to v.maxAgeIAT. * rp: add VerifyTokens example * oidc: add standard references to: - IDTokenClaims - IntrospectionResponse - UserInfo * only count coverage for `./pkg/...`
- Loading branch information
Showing
55 changed files
with
2,344 additions
and
1,502 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
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
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
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
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 |
---|---|---|
@@ -1,22 +1,36 @@ | ||
module github.com/zitadel/oidc/v2 | ||
|
||
go 1.16 | ||
go 1.18 | ||
|
||
require ( | ||
github.com/golang/mock v1.6.0 | ||
github.com/google/go-cmp v0.5.2 // indirect | ||
github.com/google/go-github/v31 v31.0.0 | ||
github.com/google/uuid v1.3.0 | ||
github.com/gorilla/mux v1.8.0 | ||
github.com/gorilla/schema v1.2.0 | ||
github.com/gorilla/securecookie v1.1.1 | ||
github.com/jeremija/gosubmit v0.2.7 | ||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect | ||
github.com/muhlemmer/gu v0.3.0 | ||
github.com/rs/cors v1.8.3 | ||
github.com/sirupsen/logrus v1.9.0 | ||
github.com/stretchr/testify v1.8.1 | ||
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 | ||
golang.org/x/text v0.6.0 | ||
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect | ||
gopkg.in/square/go-jose.v2 v2.6.0 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/golang/protobuf v1.4.2 // indirect | ||
github.com/google/go-cmp v0.5.2 // indirect | ||
github.com/google/go-querystring v1.0.0 // indirect | ||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect | ||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect | ||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect | ||
google.golang.org/appengine v1.6.6 // indirect | ||
google.golang.org/protobuf v1.25.0 // indirect | ||
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Package gen allows generating of example tokens and claims. | ||
// | ||
// go run ./internal/testutil/gen | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
tu "github.com/zitadel/oidc/v2/internal/testutil" | ||
"github.com/zitadel/oidc/v2/pkg/oidc" | ||
) | ||
|
||
var custom = map[string]any{ | ||
"foo": "Hello, World!", | ||
"bar": struct { | ||
Count int `json:"count,omitempty"` | ||
Tags []string `json:"tags,omitempty"` | ||
}{ | ||
Count: 22, | ||
Tags: []string{"some", "tags"}, | ||
}, | ||
} | ||
|
||
func main() { | ||
enc := json.NewEncoder(os.Stdout) | ||
enc.SetIndent("", " ") | ||
|
||
accessToken, atClaims := tu.NewAccessTokenCustom( | ||
tu.ValidIssuer, tu.ValidSubject, tu.ValidAudience, | ||
tu.ValidExpiration.AddDate(99, 0, 0), tu.ValidJWTID, | ||
tu.ValidClientID, tu.ValidSkew, custom, | ||
) | ||
atHash, err := oidc.ClaimHash(accessToken, tu.SignatureAlgorithm) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
idToken, idClaims := tu.NewIDTokenCustom( | ||
tu.ValidIssuer, tu.ValidSubject, tu.ValidAudience, | ||
tu.ValidExpiration.AddDate(99, 0, 0), tu.ValidAuthTime, | ||
tu.ValidNonce, tu.ValidACR, tu.ValidAMR, tu.ValidClientID, | ||
tu.ValidSkew, atHash, custom, | ||
) | ||
|
||
fmt.Println("access token claims:") | ||
if err := enc.Encode(atClaims); err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("access token:\n%s\n", accessToken) | ||
|
||
fmt.Println("ID token claims:") | ||
if err := enc.Encode(idClaims); err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("ID token:\n%s\n", idToken) | ||
} |
Oops, something went wrong.