🛠️
Technical Documentation
  • Introduction
    • About Empeiria
  • Empe Blockchain
    • Overview
    • Chain Architecture
      • Auth
      • Authz
      • Bank
      • Distribution
      • Governance
      • Staking
      • IBC
      • DidDoc
      • Vesting
      • Minter
  • EVDI
    • EVDI Architecture
    • Self-Sovereign Identity
      • Technical Foundations
      • Roles in the SSI framework
      • Protocols and Standards
  • User Guide
    • Empe DID Wallet
      • Intro
      • Download and first launch
      • Create or import did
      • Main screen overview
      • How to claim credential from issuer
      • How to use credential with verifier
      • Settings and other options
    • Keplr Wallet and Blockchain Operations
      • How to Connect Keplr Wallet
    • Ping Pub operation
    • Staking Tokens Guide
    • Voting on Governance Proposals Guide
    • Sending Tokens Guide
  • Developer Guide
    • Tutorial: Credential Issuance & Verification
      • Overview
      • Understanding Key Concepts
      • Project Setup
      • Deploying the Issuer
      • Uploading the Credential Schema
      • Issuing Credentials
      • Frontend for Credential Issuance
      • Testing Credential Issuance
      • Deploying the Verifier
      • Setting Up the Verification Flow
      • Creating a Verification Endpoint
      • Creating a Protected Dashboard
      • Testing the Verification Flow
      • Summary & Next Steps
    • One-click deployment
      • Introduction
      • Registration
      • Login
      • Creating an Issuer
      • Issuer Data Description
      • Creating a Verifier
      • Verifier Data Description
    • Verifier
      • Terminology and Concepts
      • Architecture Overview
      • Core Responsibilities
      • Query Language
      • Frontend Integration
      • Client Configuration
      • Security Considerations
      • Error Handling and Troubleshooting
      • Future Enhancements
      • References and Standards
      • FAQ
    • Issuer
      • Terminology and Concepts
      • Architecture Overview
      • Core Responsibilities
      • DID Document Management
      • Schemas Management
      • Issuing Credentials
      • Interacting with Wallets
      • Security Considerations
      • Error Handling and Troubleshooting
      • Future Enhancements
      • References and Standards
      • FAQ
    • Wallet SDK (Coming soon)
    • Introduction to cosmwasm
  • Validator Guide
    • Important links
    • Validators Guide
      • New validator
      • Hardware requirements
      • Required software installation
      • Go installation
      • Install prebuild binary
      • Install binary from source code (option B)
      • Configure a node
      • Cosmovisor setup
      • Sync with state-sync
      • Full state sync from archive snapshot
      • Latest snapshot
      • Run a Validator
      • Migration to v0.2.2
      • Migration to v0.3.0
    • FAQ
  • Appendix
    • Glossary
Powered by GitBook
On this page
  1. Developer Guide
  2. Tutorial: Credential Issuance & Verification

Creating a Protected Dashboard

What We Are Doing:

  • Adding a protected resource (e.g., /dashboard) that only verified users can access.

  • Decoding the access_token to display user information extracted from the credential.

Why: To show the end result of verification, we`ll display a dashboard page that uses the credential data.

Steps: Create public/dashboard.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Dashboard</title>
</head>
<body>
  <h2>Welcome to the Dashboard!</h2>
  <p>DID: <span id="did"></span></p>
  <p>First Name: <span id="first-name"></span></p>
  <p>Last Name: <span id="last-name"></span></p>
  <p>Age: <span id="age"></span></p>

  <script>
    (async () => {
      const token = localStorage.getItem("access_token");
      if (!token) return;

      const res = await fetch('/decode-access-token', {
        headers: { Authorization: `Bearer ${token}` }
      });
      const data = await res.json();
      document.getElementById("did").innerText = data.did;
      document.getElementById("first-name").innerText = data.formData.firstName;
      document.getElementById("last-name").innerText = data.formData.lastName;
      document.getElementById("age").innerText = data.formData.age;
    })();
  </script>
</body>
</html>

Add a route to decode the token and extract data in src/routes.ts:

import jwt from "jsonwebtoken";
import { VerifiablePresentation } from "@empe/identity";

router.get("/decode-access-token", (req: Request, res: Response) => {
  const authHeader = req.headers["authorization"];
  const access_token = authHeader?.split(" ")[1];
  if (!access_token) res.status(401).json({ error: "Unauthorized" });

  try {
    const decoded = jwt.verify(access_token, "your-jwt-secret") as jwt.JwtPayload;
    let formData: Record<string, any> = {};

    if (decoded.vp) {
      const vp = VerifiablePresentation.fromJSON(decoded.vp);
      vp.verifiableCredentials().forEach((vc) => {
        formData = { ...formData, ...vc.credentialSubject() };
      });
    }

    res.json({
      did: decoded.sub,
      formData,
    });
  } catch (error) {
    res.status(500).json({ error: "Internal server error" });
  }
});

router.get("/dashboard", (req: Request, res: Response) => {
  res.sendFile("dashboard.html", { root: "public" });
});

Now, after verification, the user is redirected to /dashboard, and their credential info is displayed.

PreviousCreating a Verification EndpointNextTesting the Verification Flow

Last updated 3 months ago