Skip to content

Commit

Permalink
Merge pull request #333 from esune/fix/names-array-mappings
Browse files Browse the repository at this point in the history
Fix/names array mappings
  • Loading branch information
esune authored Sep 14, 2023
2 parents dc1ca7a + 79f94e0 commit ae8cd53
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
4 changes: 2 additions & 2 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ services:
#
# The following parameter addresses a redirect error on logout in later (post KC 16 at least).
# It may be fixable by updating the vue app as well -- google "keycloak error Invalid parameter: redirect_uri"
KC_SPI_LOGIN_PROTOCOL_OPENID_CONNECT_LEGACY_LOGOUT_REDIRECT_URI: true
KC_SPI_LOGIN_PROTOCOL_OPENID_CONNECT_LEGACY_LOGOUT_REDIRECT_URI: "true"
depends_on:
- keycloak-db
networks:
Expand Down Expand Up @@ -98,7 +98,7 @@ services:
- ACAPY_WALLET_STORAGE_TYPE=${WALLET_TYPE}
- ACAPY_READ_ONLY_LEDGER=true
- ACAPY_GENESIS_TRANSACTIONS_LIST=/tmp/ledgers.yaml
- ACAPY_LOG_LEVEL=debug
- ACAPY_LOG_LEVEL=info
- ACAPY_WEBHOOK_URL=${CONTROLLER_WEB_HOOK_URL}
- ACAPY_AUTO_PROVISION=true
- POSTGRESQL_WALLET_HOST=${POSTGRESQL_WALLET_HOST}
Expand Down
10 changes: 6 additions & 4 deletions oidc-controller/api/core/acapy/client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import requests
import json
import structlog
from typing import Optional, Union
from uuid import UUID
from .models import WalletDid, CreatePresentationResponse

import requests
import structlog

from ..config import settings
from .config import AgentConfig, MultiTenantAcapy, SingleTenantAcapy
from .models import CreatePresentationResponse, WalletDid

_client = None
logger = structlog.getLogger(__name__)
Expand Down Expand Up @@ -67,7 +69,7 @@ def get_presentation_request(self, presentation_exchange_id: Union[UUID, str]):
assert resp_raw.status_code == 200, resp_raw.content
resp = json.loads(resp_raw.content)

logger.debug("<<< get_presentation_request -> {resp}")
logger.debug(f"<<< get_presentation_request -> {resp}")
return resp

def verify_presentation(self, presentation_exchange_id: Union[UUID, str]):
Expand Down
5 changes: 5 additions & 0 deletions oidc-controller/api/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ class TimestampModel(BaseModel):

class GenericErrorMessage(BaseModel):
detail: str


class RevealedAttribute(BaseModel):
sub_proof_index: int
values: dict
51 changes: 37 additions & 14 deletions oidc-controller/api/core/oidc/issue_token_service.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import structlog
import dataclasses
import json
import uuid
import dataclasses
from datetime import datetime
from typing import List, Dict, Any
from pydantic import BaseModel
from typing import Any, Dict, List

import structlog
from oic.oic.message import OpenIDSchema
from pydantic import BaseModel

from ...authSessions.models import AuthSession
from ...verificationConfigs.models import VerificationConfig
from ...verificationConfigs.models import ReqAttr, VerificationConfig
from ..models import RevealedAttribute

logger = structlog.getLogger(__name__)

Expand Down Expand Up @@ -52,16 +55,36 @@ def get_claims(
]
)

for referent, requested_attr in auth_session.presentation_exchange[
"presentation_request"
]["requested_attributes"].items():
# loop through each value and put it in token as a claim
revealed_attrs: Dict[str, Any] = auth_session.presentation_exchange[
"presentation"
]["requested_proof"]["revealed_attrs"]
presentation_claims[requested_attr["name"]] = Claim(
type=requested_attr["name"], value=revealed_attrs[referent]["raw"]
referent: str
requested_attr: ReqAttr
try:
for referent, requested_attr in auth_session.presentation_exchange[
"presentation_request"
]["requested_attributes"].items():
logger.debug(
f"Processing referent: {referent}, requested_attr: {requested_attr}"
)
revealed_attrs: Dict[
str, RevealedAttribute
] = auth_session.presentation_exchange["presentation"][
"requested_proof"
][
"revealed_attr_groups"
]
logger.debug(f"revealed_attrs: {revealed_attrs}")
# loop through each value and put it in token as a claim
for attr_name in requested_attr["names"]:
logger.debug(f"AttrName: {attr_name}")
presentation_claims[attr_name] = Claim(
type=attr_name,
value=revealed_attrs[referent]["values"][attr_name]["raw"],
)
logger.debug(f"Compiled presentation_claims: {presentation_claims}")
except Exception as err:
logger.error(
f"An exception occurred while extracting the proof claims: {err}"
)
raise RuntimeError(err)

# look at all presentation_claims and one should
# match the configured subject_identifier
Expand Down
1 change: 1 addition & 0 deletions oidc-controller/api/routers/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@ async def post_token(request: Request, db: Database = Depends(get_db)):
token_response = provider.provider.handle_token_request(
data, request.headers, claims
)
logger.debug(f"Token response: {token_response.to_dict()}")
return token_response.to_dict()

0 comments on commit ae8cd53

Please sign in to comment.