-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: OID4VCI combining metadata file (#1438)
Signed-off-by: Mykhailo Sizov <mykhailo.sizov@securekey.com>
- Loading branch information
1 parent
14a101b
commit 9376d3a
Showing
24 changed files
with
460 additions
and
1,091 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Copyright Avast Software. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package walletrunner | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
vdrapi "github.com/trustbloc/did-go/vdr/api" | ||
"github.com/trustbloc/vc-go/jwt" | ||
"github.com/trustbloc/vc-go/verifiable" | ||
"github.com/valyala/fastjson" | ||
|
||
issuerv1 "github.com/trustbloc/vcs/pkg/restapi/v1/issuer" | ||
) | ||
|
||
// GetWellKnownOpenIDConfiguration returns OIDC Configuration. | ||
func (s *Service) GetWellKnownOpenIDConfiguration( | ||
issuerURL string, | ||
) (*issuerv1.WellKnownOpenIDIssuerConfiguration, error) { | ||
// GET /issuer/{profileID}/.well-known/openid-credential-issuer | ||
resp, err := s.httpClient.Get(issuerURL + "/.well-known/openid-credential-issuer") | ||
if err != nil { | ||
return nil, fmt.Errorf("get issuer well-known: %w", err) | ||
} | ||
|
||
defer func() { | ||
_ = resp.Body.Close() | ||
}() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("get issuer well-known: status code %d", resp.StatusCode) | ||
} | ||
|
||
var oidcConfig issuerv1.WellKnownOpenIDIssuerConfiguration | ||
|
||
wellKnownOpenIDIssuerConfigurationPayload, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, fmt.Errorf("read issuer configuration payload body: %w", err) | ||
} | ||
|
||
if jwt.IsJWS(string(wellKnownOpenIDIssuerConfigurationPayload)) { | ||
wellKnownOpenIDIssuerConfigurationPayload, err = | ||
getWellKnownOpenIDConfigurationJWTPayload( | ||
string(wellKnownOpenIDIssuerConfigurationPayload), s.ariesServices.vdrRegistry) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
if err = json.Unmarshal(wellKnownOpenIDIssuerConfigurationPayload, &oidcConfig); err != nil { | ||
return nil, fmt.Errorf("decode issuer well-known: %w", err) | ||
} | ||
|
||
return &oidcConfig, nil | ||
} | ||
|
||
func getWellKnownOpenIDConfigurationJWTPayload(rawResponse string, vdrRegistry vdrapi.Registry) ([]byte, error) { | ||
jwtVerifier := jwt.NewVerifier(jwt.KeyResolverFunc( | ||
verifiable.NewVDRKeyResolver(vdrRegistry).PublicKeyFetcher())) | ||
|
||
_, credentialOfferPayload, err := jwt.Parse( | ||
rawResponse, | ||
jwt.WithSignatureVerifier(jwtVerifier), | ||
jwt.WithIgnoreClaimsMapDecoding(true), | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("parse issuer configuration JWT: %w", err) | ||
} | ||
|
||
var fastParser fastjson.Parser | ||
v, err := fastParser.ParseBytes(credentialOfferPayload) | ||
if err != nil { | ||
return nil, fmt.Errorf("decode claims: %w", err) | ||
} | ||
|
||
sb, err := v.Get("well_known_openid_issuer_configuration").Object() | ||
if err != nil { | ||
return nil, fmt.Errorf("fastjson.Parser Get well_known_openid_issuer_configuration: %w", err) | ||
} | ||
|
||
return sb.MarshalTo([]byte{}), nil | ||
} |
Oops, something went wrong.