Skip to content

Commit

Permalink
Merge pull request #3 from oidc-mytoken/dev
Browse files Browse the repository at this point in the history
0.7
  • Loading branch information
zachmann committed Jan 17, 2023
2 parents f5d5468 + 81d8db5 commit eee0e96
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2022 Gabriel Zachmann
Copyright (c) 2020-2023 Gabriel Zachmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/oidc-mytoken/lib

go 1.13

require github.com/oidc-mytoken/api v0.9.1
require github.com/oidc-mytoken/api v0.10.0
9 changes: 7 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/oidc-mytoken/api v0.9.1 h1:Hmv+KaGyxiodf92mXjELFeZOa9tBsQnUyEoBAFQNls8=
github.com/oidc-mytoken/api v0.9.1/go.mod h1:DBIlUbaIgGlf607VZx8zFC97VR3WNN0kaMVO1AqyTdE=
github.com/oidc-mytoken/api v0.10.0 h1:+LCMb7et/roU+Baifho9bcOOAoqDzMSOJt4T1EgI5nk=
github.com/oidc-mytoken/api v0.10.0/go.mod h1:DS2/0gUjt84jVq/4jqs7mSoUtv1DDEp3xexF7HW1qe4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
12 changes: 6 additions & 6 deletions revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ func (r RevocationEndpoint) Revoke(mytoken, oidcIssuer string, recursive bool) e
return r.DoHTTPRequest("POST", req, nil)
}

// RevokeID revokes the mytoken with the passed revocation id; using the passed mytoken as authorization; if
// RevokeID revokes the mytoken with the passed mom id; using the passed mytoken as authorization; if
// recursive is true also all subtokens (and their subtokens...) are revoked.
func (r RevocationEndpoint) RevokeID(revocationID, mytoken, oidcIssuer string, recursive bool) error {
func (r RevocationEndpoint) RevokeID(momID, mytoken, oidcIssuer string, recursive bool) error {
req := api.RevocationRequest{
RevocationID: revocationID,
Token: mytoken,
Recursive: recursive,
OIDCIssuer: oidcIssuer,
MOMID: momID,
Token: mytoken,
Recursive: recursive,
OIDCIssuer: oidcIssuer,
}
return r.DoHTTPRequest("POST", req, nil)
}
29 changes: 25 additions & 4 deletions tokeninfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,49 @@ func (info TokeninfoEndpoint) Introspect(mytoken string) (*api.TokeninfoIntrospe
return &resp, nil
}

// APIHistory obtains the event history for the passed mytoken.
// APIHistory obtains the event history for the passed mytoken or mom id.
// If the used mytoken changes (due to token rotation), the new mytoken is included in the api.TokeninfoHistoryResponse
func (info TokeninfoEndpoint) APIHistory(mytoken string) (resp api.TokeninfoHistoryResponse, err error) {
func (info TokeninfoEndpoint) APIHistory(mytoken string, momID ...string) (
resp api.TokeninfoHistoryResponse, err error,
) {
var mom string
if len(momID) > 0 {
mom = momID[0]
}
req := api.TokenInfoRequest{
Action: api.TokeninfoActionEventHistory,
Mytoken: mytoken,
MOMID: mom,
}
err = info.DoHTTPRequest("POST", req, &resp)
return
}

// History obtains the event history for the passed mytoken.
// If the used mytoken changes (due to token rotation), the passed variable is updated accordingly.
func (info TokeninfoEndpoint) History(mytoken *string) (api.EventHistory, error) {
func (info TokeninfoEndpoint) History(mytoken *string) ([]api.EventEntry, error) {
resp, err := info.APIHistory(*mytoken)
if err != nil {
return nil, err
}
if resp.TokenUpdate != nil {
*mytoken = resp.TokenUpdate.Mytoken
}
return resp.EventHistory, nil
return resp.EventHistory.Events, nil
}

// HistoryForOtherMytoken obtains the event history for mytoken with the passed mom id and uses the passed mytoken as
// authorization.
// If the used mytoken changes (due to token rotation), the passed variable is updated accordingly.
func (info TokeninfoEndpoint) HistoryForOtherMytoken(mytoken *string, momID string) (*api.EventHistory, error) {
resp, err := info.APIHistory(*mytoken, momID)
if err != nil {
return nil, err
}
if resp.TokenUpdate != nil {
*mytoken = resp.TokenUpdate.Mytoken
}
return &resp.EventHistory, nil
}

// APISubtokens returns an api.TokeninfoTreeResponse listing metadata about the passed mytoken and its children (
Expand Down

0 comments on commit eee0e96

Please sign in to comment.