Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
feat: Add new demo page to handle issuance initiate request
Browse files Browse the repository at this point in the history
Signed-off-by: Talwinder Kaur <[email protected]>
  • Loading branch information
Talwinder kaur committed Sep 15, 2022
1 parent 9e98097 commit 8a9f5fa
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/mock/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
waciIssuerHTML = "./templates/issuer/waci-issuer.html"
oidcIssuerHTML = "./templates/issuer/oidc-issuer.html"
oidcIssuerLoginHTML = "./templates/issuer/oidc-login.html"
openIDvcHTML = "./templates/issuer/openid-initiate-request.html"

// verifier html templates
verifierHTML = "./templates/verifier/verifier.html"
Expand Down Expand Up @@ -82,6 +83,13 @@ type issuerConfiguration struct {
CredentialManifests json.RawMessage `json:"credential_manifests"`
}

type issuanceInitiationRequest struct {
Issuer string `json:"issuer"`
CredentialType string `json:"credential_type"`
UserPinRequired bool `json:"user_pin_required"`
PreAuthorizedCode string `json:"pre-authorized_code"`
}

// waciIssuanceData contains state of WACI demo.
type waciIssuanceData struct {
CredentialManifest json.RawMessage `json:"credential_manifest"`
Expand Down Expand Up @@ -133,7 +141,9 @@ func startAdapterApp(agent *didComm, router *mux.Router) error {
router.HandleFunc("/issuer/waci-issuance/{id}", app.waciIssuanceCallback)
router.HandleFunc("/issuer/oidc", app.oidcIssuer)
router.HandleFunc("/issuer/oidc/login", app.oidcIssuerLogin)
router.HandleFunc("/issuer/openid/vc", app.openIDVC)
router.HandleFunc("/issuer/oidc/issuance", app.initiateIssuance).Methods(http.MethodPost)
router.HandleFunc("/issuance/initiate", app.issuanceInitiate).Methods(http.MethodPost)
router.HandleFunc("/{id}/.well-known/openid-configuration", app.wellKnownConfiguration).Methods(http.MethodGet)
router.HandleFunc("/{id}/issuer/oidc/authorize", app.issuerAuthorize).Methods(http.MethodGet)
router.HandleFunc("/issuer/oidc/authorize-request", app.issuerSendAuthorizeResponse).Methods(http.MethodPost)
Expand Down Expand Up @@ -173,6 +183,10 @@ func (v *adapterApp) oidcIssuerLogin(w http.ResponseWriter, r *http.Request) {
loadTemplate(w, oidcIssuerLoginHTML, nil)
}

func (v *adapterApp) openIDVC(w http.ResponseWriter, r *http.Request) {
loadTemplate(w, openIDvcHTML, nil)
}

// verifier html template endpoints
func (v *adapterApp) verifier(w http.ResponseWriter, r *http.Request) {
loadTemplate(w, verifierHTML, nil)
Expand Down Expand Up @@ -482,6 +496,52 @@ func (v *adapterApp) oidcShareCallback(w http.ResponseWriter, r *http.Request) {
)
}

func (v *adapterApp) issuanceInitiate(w http.ResponseWriter, r *http.Request) {
r.ParseForm()

walletURL := r.FormValue("walletInitIssuanceURL")
credentialType := r.FormValue("credentialType")
issuerURL := r.FormValue("issuerURL")

key := uuid.NewString()
issuer := issuerURL + "/" + key
issuerConf, err := json.MarshalIndent(&issuanceInitiationRequest{
Issuer: issuer,
CredentialType: credentialType,
UserPinRequired: false,
PreAuthorizedCode: uuid.NewString(),
}, "", " ")
if err != nil {
handleError(w, http.StatusInternalServerError,
fmt.Sprintf("failed to prepare issuer issuance initiation request : %s", err))

return
}

err = v.store.Put(key, issuerConf)
if err != nil {
handleError(w, http.StatusInternalServerError,
fmt.Sprintf("failed to prepare server configuration : %s", err))

return
}

u, err := url.Parse(walletURL)
if err != nil {
handleError(w, http.StatusInternalServerError,
fmt.Sprintf("failed to parse wallet init issuance URL : %s", err))

return
}

q := u.Query()
q.Set("issuer", issuer)

u.RawQuery = q.Encode()

http.Redirect(w, r, u.String(), http.StatusFound)
}

func (v *adapterApp) initiateIssuance(w http.ResponseWriter, r *http.Request) {
r.ParseForm()

Expand Down
53 changes: 53 additions & 0 deletions test/mock/adapter/templates/issuer/openid-initiate-request.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo Open ID For VC</title>
<script type="text/javascript">
function setIssuerURL(action) {
document.getElementById("issuerURL").value =
location.protocol + "//" + location.host;
}
</script>
</head>
<body>

<h1>OPENID4VC DEMO</h1>
<form action="/issuance/initiate" id="oidc-issuance-form" method="POST">
<input type="hidden" id="issuerURL" name="issuerURL" value="" />
<table style="border-spacing: 10px">
<tr>
<td><label>Wallet Initiate Issuance URL</label></td>
<td>
<input
type="text"
id="walletURL"
name="walletInitIssuanceURL"
value="https://wallet.trustbloc.local:8091/oidc/initiate"
size="50"
/>
</td>
</tr>
<tr>
<td><label>Credential Types</label></td>
<td>
<input
type="text"
id="credentialTypes"
name="credentialTypes"
value="https://w3id.org/citizenship/v1"
size="50"
/>
</td>
</tr>

</table>
<input
type="submit"
id="openid-issuance"
value="Demo"
onclick="javascript:setIssuerURL()"
/>
</form>
</body>
</html>

0 comments on commit 8a9f5fa

Please sign in to comment.