forked from digitalocean/sample-flask
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.pyc | ||
__pycache__/* | ||
key.* |
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,51 @@ | ||
from datetime import datetime, timedelta | ||
import didkit | ||
import json | ||
import stripe | ||
import uuid | ||
|
||
|
||
def issueCredential(request): | ||
session_id = request.args.get("session_id") | ||
session_data = stripe.checkout.Session.retrieve(session_id) | ||
|
||
with open('key.jwk', "r") as f: | ||
key = f.readline() | ||
f.close() | ||
|
||
did_key = request.form.get('subject_id', didkit.keyToDID("key", key)) | ||
verification_method = didkit.keyToVerificationMethod("key", key) | ||
issuance_date = datetime.utcnow().replace(microsecond=0) | ||
expiration_date = issuance_date + timedelta(weeks=4) | ||
|
||
credential = { | ||
"id": "urn:uuid:" + uuid.uuid4().__str__(), | ||
"@context": [ | ||
"https://www.w3.org/2018/credentials/v1", | ||
"https://www.w3.org/2018/credentials/examples/v1", | ||
], | ||
"type": ["VerifiableCredential"], | ||
"issuer": did_key, | ||
"issuanceDate": issuance_date.isoformat() + "Z", | ||
"expirationDate": expiration_date.isoformat() + "Z", | ||
"credentialSubject": { | ||
"@context": [ | ||
{ | ||
"email": "https://schema.org/Text" | ||
} | ||
], | ||
"id": "urn:uuid:" + uuid.uuid4().__str__(), | ||
"email": session_data["customer_details"]["email"] | ||
}, | ||
} | ||
|
||
didkit_options = { | ||
"proofPurpose": "assertionMethod", | ||
"verificationMethod": verification_method, | ||
} | ||
|
||
credential = didkit.issueCredential( | ||
credential.__str__().replace("'", '"'), | ||
didkit_options.__str__().replace("'", '"'), | ||
key) | ||
return json.loads(credential) |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"> | ||
<script src="https://js.stripe.com/v3/"></script> | ||
<script src="{{ url_for('static', filename='main.js') }}"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/credential-handler-polyfill.min.js"></script> | ||
</head> | ||
<body class="w-screen h-screen items-center justify-center flex"> | ||
{% block content %}{% endblock %} | ||
|
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,5 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<pre class="whitespace-pre-wrap m-auto">{{ credential }}</pre> | ||
{% endblock %} |