Skip to content

Commit

Permalink
Rewritten redirect_endpoint and request_endpoint to use JWT helper cl…
Browse files Browse the repository at this point in the history
…asses
  • Loading branch information
pderose committed Jul 19, 2023
1 parent 678e2f8 commit 6f65b8c
Showing 1 changed file with 68 additions and 5 deletions.
73 changes: 68 additions & 5 deletions eudi_wallet_python/satosa/backend.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import logging
import json
import base64
import logging

from urllib.parse import urlencode, quote_plus
from satosa.exception import SATOSAAuthenticationError
from satosa.response import Response
from satosa.backends.base import BackendModule

from ..tools.jwk import JWK
from ..tools.jwt import JWSHelper

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -59,17 +63,76 @@ def qrCode_endpoint(self, context, *args):
)

def redirect_endpoint(self, context, *args):
response = '{"request": "ewogICJ0eXAiOiAiZHBvcCtqd3QiLAogICJhbGciOiAiRVMyNTYiLAogICJqd2siOiB7CiAgICAia3R5IjogIkVDIiwKICAgICJ4IjogImw4dEZyaHgtMzR0VjNoUklDUkRZOXpDa0RscEJoRjQyVVFVZldWQVdCRnMiLAogICAgInkiOiAiOVZFNGpmX09rX282NHpiVFRsY3VOSmFqSG10NnY5VERWclUwQ2R2R1JEQSIsCiAgICAiY3J2IjogIlAtMjU2IgogIH0KfQ.ewogICJqdGkiOiAiZjQ3Yzk2YTEtZjkyOC00NzY4LWFhMzAtZWYzMmRjNzhhYTY5IiwKICAiaHRtIjogIkdFVCIsCiAgImh0dSI6ICJodHRwczovL3ZlcmlmaWVyLmV4YW1wbGUub3JnL3JlcXVlc3RfdXJpIiwKICAiaWF0IjogMTU2MjI2MjYxNiwKICAiYXRoIjogImZVSHlPMnIyWjNEWjUzRXNOcldCYjB4V1hvYU55NTlJaUtDQXFrc21RRW8iCn0"}'
jwk = JWK({
"typ": "dpop+jwt",
"alg": "ES256",
"jwk": {
"kty": "EC",
"x": "l8tFrhx-34tV3hRICRDY9zCkDlpBhF42UQUfWVAWBFs",
"y": "9VE4jf_Ok_o64zbTTlcuNJajHmt6v9TDVrU0CdvGRDA",
"crv": "P-256"
}
})

helper = JWSHelper(jwk)
jwt = helper.sign({
"jti": "f47c96a1-f928-4768-aa30-ef32dc78aa69",
"htm": "GET",
"htu": "https://verifier.example.org/request_uri",
"iat": 1562262616,
"ath": "fUHyO2r2Z3DZ53EsNrWBb0xWXoaNy59IiKCAqksmQEo"
},
"RS256",
)

response = {"request": jwt}

return Response(
response,
json.dumps(response),
status=200,
content="text/json; charset=utf8"
)

def request_endpoint(self, context, *args):
response = '{"response": "ewogICJhbGciOiAiRVMyNTYiLAogICJ0eXAiOiAiSldUIiwKICAia2lkIjogImUwYmJmMmYxLThjM2EtNGVhYi1hOGFjLTJlOGYzNGRiOGE0NyIKfQ.ewogICJpc3MiOiAiaHR0cHM6Ly93YWxsZXQtcHJvdmlkZXIuZXhhbXBsZS5vcmcvaW5zdGFuY2UvdmJlWEprc000NXhwaHRBTm5DaUc2bUN5dVU0amZHTnpvcEd1S3ZvZ2c5YyIsCiAgImp0aSI6ICIzOTc4MzQ0Zi04NTk2LTRjM2EtYTk3OC04ZmNhYmEzOTAzYzUiLAogICJhdWQiOiAiaHR0cHM6Ly92ZXJpZmllci5leGFtcGxlLm9yZy9jYWxsYmFjayIsCiAgImlhdCI6IDE1NDE0OTM3MjQsCiAgImV4cCI6IDE1NzMwMjk3MjMsCiAgIm5vbmNlIjogIm4tMFM2X1d6QTJNaiIsCiAgInZwIjogIjxTRC1KV1Q-fjxEaXNjbG9zdXJlIDE-fjxEaXNjbG9zdXJlIDI-fi4uLn48RGlzY2xvc3VyZSBOPiIKfQ"}'
jwk = JWK({
"typ": "dpop+jwt",
"alg": "ES256",
"jwk": {
"kty": "EC",
"x": "l8tFrhx-34tV3hRICRDY9zCkDlpBhF42UQUfWVAWBFs",
"y": "9VE4jf_Ok_o64zbTTlcuNJajHmt6v9TDVrU0CdvGRDA",
"crv": "P-256"
}
})

helper = JWSHelper(jwk)
jwt = helper.sign({
"state": "3be39b69-6ac1-41aa-921b-3e6c07ddcb03",
"vp_token": "eyJhbGciOiJFUzI1NiIs...PT0iXX0",
"presentation_submission": {
"definition_id": "32f54163-7166-48f1-93d8-ff217bdb0653",
"id": "04a98be3-7fb0-4cf5-af9a-31579c8b0e7d",
"descriptor_map": [
{
"id": "eu.europa.ec.eudiw.pid.it.1:unique_id",
"path": "$.vp_token.verified_claims.claims._sd[0]",
"format": "vc+sd-jwt"
},
{
"id": "eu.europa.ec.eudiw.pid.it.1:given_name",
"path": "$.vp_token.verified_claims.claims._sd[1]",
"format": "vc+sd-jwt"
}
]
}
},
"RS256",
)

response = {"response": jwt}

return Response(
response,
json.dumps(response),
status=200,
content="text/json; charset=utf8"
)
Expand Down

0 comments on commit 6f65b8c

Please sign in to comment.