Skip to content

Commit

Permalink
Merge pull request #1908 from bnu0/bnu-fix-etcd-pkce
Browse files Browse the repository at this point in the history
Fix the etcd PKCE AuthCode deserialization
  • Loading branch information
sagikazarmark committed Jan 13, 2021
2 parents 827889e + b45a501 commit 1fbfaa9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions storage/conformance/conformance.go
Expand Up @@ -185,6 +185,10 @@ func testAuthCodeCRUD(t *testing.T, s storage.Storage) {
Expiry: neverExpire,
ConnectorID: "ldap",
ConnectorData: []byte(`{"some":"data"}`),
PKCE: storage.PKCE{
CodeChallenge: "12345",
CodeChallengeMethod: "Whatever",
},
Claims: storage.Claims{
UserID: "1",
Username: "jane",
Expand Down
6 changes: 5 additions & 1 deletion storage/etcd/etcd.go
Expand Up @@ -156,7 +156,11 @@ func (c *conn) CreateAuthCode(a storage.AuthCode) error {
func (c *conn) GetAuthCode(id string) (a storage.AuthCode, err error) {
ctx, cancel := context.WithTimeout(context.Background(), defaultStorageTimeout)
defer cancel()
err = c.getKey(ctx, keyID(authCodePrefix, id), &a)
var ac AuthCode
err = c.getKey(ctx, keyID(authCodePrefix, id), &ac)
if err == nil {
a = toStorageAuthCode(ac)
}
return a, err
}

Expand Down
18 changes: 18 additions & 0 deletions storage/etcd/types.go
Expand Up @@ -26,6 +26,24 @@ type AuthCode struct {
CodeChallengeMethod string `json:"code_challenge_method,omitempty"`
}

func toStorageAuthCode(a AuthCode) storage.AuthCode {
return storage.AuthCode{
ID: a.ID,
ClientID: a.ClientID,
RedirectURI: a.RedirectURI,
ConnectorID: a.ConnectorID,
ConnectorData: a.ConnectorData,
Nonce: a.Nonce,
Scopes: a.Scopes,
Claims: toStorageClaims(a.Claims),
Expiry: a.Expiry,
PKCE: storage.PKCE{
CodeChallenge: a.CodeChallenge,
CodeChallengeMethod: a.CodeChallengeMethod,
},
}
}

func fromStorageAuthCode(a storage.AuthCode) AuthCode {
return AuthCode{
ID: a.ID,
Expand Down

0 comments on commit 1fbfaa9

Please sign in to comment.