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 a30823a
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
59 changes: 59 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"
oidcIssuerV2HTML = "./templates/issuer/oidc-issuer-v2.html"

// verifier html templates
verifierHTML = "./templates/verifier/verifier.html"
Expand Down Expand Up @@ -133,7 +134,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/oidc/v2", app.openIssuerV2)
router.HandleFunc("/issuer/oidc/issuance", app.initiateIssuance).Methods(http.MethodPost)
router.HandleFunc("/issuer/oidc/issuance/v2", app.initiateIssuanceV2).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 +176,10 @@ func (v *adapterApp) oidcIssuerLogin(w http.ResponseWriter, r *http.Request) {
loadTemplate(w, oidcIssuerLoginHTML, nil)
}

func (v *adapterApp) openIssuerV2(w http.ResponseWriter, r *http.Request) {
loadTemplate(w, oidcIssuerV2HTML, 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 +489,58 @@ func (v *adapterApp) oidcShareCallback(w http.ResponseWriter, r *http.Request) {
)
}

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

walletURL := r.FormValue("walletInitIssuanceURL")
credentialTypes := strings.Split(r.FormValue("credentialTypes"), ",")
issuerURL := r.FormValue("issuerURL")

key := uuid.NewString()
issuer := issuerURL + "/" + key
issuerConf, err := json.MarshalIndent(&issuerConfiguration{
Issuer: issuer,
AuthorizationEndpoint: issuer + "/issuer/oidc/authorize",
TokenEndpoint: issuer + "/issuer/oidc/token",
CredentialEndpoint: issuer + "/issuer/oidc/credential",
}, "", " ")
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)

for _, credType := range credentialTypes {
q.Add("credential_type", credType)
}

u.RawQuery = q.Encode()

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
71 changes: 71 additions & 0 deletions test/mock/adapter/templates/issuer/oidc-issuer-v2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!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="/issuer/oidc/issuance/v2" 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>

</head>
<div style="position:absolute; left:800px; top:100px;"> <button class="button qrCodeButton">Scan Your QR Code</button></div>

</body>
<style>
.button {
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.qrCodeButton {background-color: #008CBA;}
</style>
</html>

0 comments on commit a30823a

Please sign in to comment.