Skip to content

Commit

Permalink
fix: make tid and oid optional to allow User validation in B2C (#145)
Browse files Browse the repository at this point in the history
* fix: make  and  optional to allow User validation in B2C

* fix: adjust testing the openapi schema with optional tid and oid claims
  • Loading branch information
davidhuser authored Jul 31, 2023
1 parent 474e14c commit d4d185f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
8 changes: 4 additions & 4 deletions fastapi_azure_auth/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ class Claims(BaseModel):
...,
description='The principal associated with the token.',
)
oid: str = Field(
...,
oid: Optional[str] = Field(
default=None,
description='The immutable identifier for the requestor, which is the verified identity of the user or service principal',
)
tid: str = Field(
...,
tid: Optional[str] = Field(
default=None,
description='Represents the tenant that the user is signing in to',
)
uti: Optional[str] = Field(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_openapi_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@
'description': 'The principal associated with the token.',
},
'oid': {
'type': 'string',
'anyOf': [{'type': 'string'}, {'type': 'null'}],
'title': 'Oid',
'description': 'The immutable identifier for the requestor, which is the verified identity of the user or service principal',
},
'tid': {
'type': 'string',
'anyOf': [{'type': 'string'}, {'type': 'null'}],
'title': 'Tid',
'description': 'Represents the tenant that the user is signing in to',
},
Expand Down Expand Up @@ -383,7 +383,7 @@
},
},
'type': 'object',
'required': ['aud', 'iss', 'iat', 'nbf', 'exp', 'sub', 'oid', 'tid', 'ver', 'claims', 'access_token'],
'required': ['aud', 'iss', 'iat', 'nbf', 'exp', 'sub', 'ver', 'claims', 'access_token'],
'title': 'User',
},
},
Expand Down
2 changes: 0 additions & 2 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ def get_utc_now_as_unix_timestamp() -> int:
def test_user_missing_optionals():
user = User(
aud='Dummy',
tid='Dummy',
access_token='Dummy',
claims={'oid': 'Dummy oid'},
iss='https://dummy-platform.dummylogin.com/dummy-uid/v2.0/',
iat=get_utc_now_as_unix_timestamp(),
nbf=get_utc_now_as_unix_timestamp(),
exp=get_utc_now_as_unix_timestamp(),
sub='dummy-sub',
oid='dummy-oid',
ver='1.0',
scp='AccessAsUser',
)
Expand Down

0 comments on commit d4d185f

Please sign in to comment.