-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: verifiable credentials JWT format (#3614)
- Loading branch information
Showing
3 changed files
with
132 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package oauth2 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/golang-jwt/jwt/v5" | ||
|
||
"github.com/ory/fosite" | ||
) | ||
|
||
// Request a Verifiable Credential | ||
// | ||
// swagger:parameters createVerifiableCredential | ||
// | ||
//lint:ignore U1000 Used to generate Swagger and OpenAPI definitions | ||
type createVerifiableCredentialRequest struct { | ||
// in: body | ||
Body CreateVerifiableCredentialRequestBody | ||
} | ||
|
||
// CreateVerifiableCredentialRequestBody contains the request body to request a verifiable credential. | ||
// | ||
// swagger:parameters createVerifiableCredentialRequestBody | ||
type CreateVerifiableCredentialRequestBody struct { | ||
Format string `json:"format"` | ||
Types []string `json:"types"` | ||
Proof *VerifiableCredentialProof `json:"proof"` | ||
} | ||
|
||
// VerifiableCredentialProof contains the proof of a verifiable credential. | ||
// | ||
// swagger:parameters verifiableCredentialProof | ||
type VerifiableCredentialProof struct { | ||
ProofType string `json:"proof_type"` | ||
JWT string `json:"jwt"` | ||
} | ||
|
||
// VerifiableCredentialResponse contains the verifiable credential. | ||
// | ||
// swagger:model verifiableCredentialResponse | ||
type VerifiableCredentialResponse struct { | ||
Format string `json:"format"` | ||
Credential string `json:"credential_draft_00"` | ||
} | ||
|
||
// VerifiableCredentialPrimingResponse contains the nonce to include in the proof-of-possession JWT. | ||
// | ||
// swagger:model verifiableCredentialPrimingResponse | ||
type VerifiableCredentialPrimingResponse struct { | ||
Format string `json:"format"` | ||
Nonce string `json:"c_nonce"` | ||
NonceExpiresIn int64 `json:"c_nonce_expires_in"` | ||
|
||
fosite.RFC6749ErrorJson | ||
} | ||
|
||
type VerifableCredentialClaims struct { | ||
jwt.RegisteredClaims | ||
VerifiableCredential VerifiableCredentialClaim `json:"vc"` | ||
} | ||
type VerifiableCredentialClaim struct { | ||
Context []string `json:"@context"` | ||
Subject map[string]any `json:"credentialSubject"` | ||
Type []string `json:"type"` | ||
} | ||
|
||
func (v *VerifableCredentialClaims) GetAudience() (jwt.ClaimStrings, error) { | ||
return jwt.ClaimStrings{}, nil | ||
} | ||
|
||
func (v *VerifableCredentialClaims) ToMapClaims() (res map[string]any, err error) { | ||
res = map[string]any{} | ||
|
||
bs, err := json.Marshal(v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = json.Unmarshal(bs, &res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |