Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/OpenG2P/openg2p-portal-api
Browse files Browse the repository at this point in the history
… into develop-0.5
  • Loading branch information
Q-Niranjan committed Dec 10, 2024
2 parents 5ea3822 + f77f83b commit 6d3c652
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 7 deletions.
141 changes: 140 additions & 1 deletion api-docs/generated/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,119 @@
}
}
},
"/uploadDocument/{programid}": {
"post": {
"tags": [
"document"
],
"summary": "Upload Document",
"operationId": "upload_document_uploadDocument__programid__post",
"security": [
{
"JwtBearerAuth": []
}
],
"parameters": [
{
"name": "programid",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"title": "Programid"
}
},
{
"name": "file_tag",
"in": "query",
"required": false,
"schema": {
"type": "string",
"title": "File Tag"
}
}
],
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"$ref": "#/components/schemas/Body_upload_document_uploadDocument__programid__post"
}
}
}
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DocumentFile"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/getDocument/{document_id}": {
"get": {
"tags": [
"document"
],
"summary": "Get Document By Id",
"operationId": "get_document_by_id_getDocument__document_id__get",
"security": [
{
"JwtBearerAuth": []
}
],
"parameters": [
{
"name": "document_id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"title": "Document Id"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DocumentFile"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/auth/profile": {
"get": {
"tags": [
Expand Down Expand Up @@ -1542,6 +1655,33 @@
"type": "object",
"title": "BenefitDetails"
},
"Body_upload_document_uploadDocument__programid__post": {
"properties": {
"file": {
"type": "string",
"format": "binary",
"title": "File"
}
},
"type": "object",
"required": [
"file"
],
"title": "Body_upload_document_uploadDocument__programid__post"
},
"DocumentFile": {
"properties": {
"name": {
"type": "string",
"title": "Name"
}
},
"type": "object",
"required": [
"name"
],
"title": "DocumentFile"
},
"ErrorListResponse": {
"properties": {
"errors": {
Expand Down Expand Up @@ -1784,7 +1924,6 @@
"enum": [
"oauth2_auth_code"
],
"const": "oauth2_auth_code",
"title": "LoginProviderTypes"
},
"PhoneNumber": {
Expand Down
6 changes: 5 additions & 1 deletion src/openg2p_portal_api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ async def __call__(
message="Unauthorized. Invalid Auth Provider. ID Type not configured."
)

mapped_res = AuthOauthProviderORM.map_validation_response(
res.model_dump(), id_type_config["token_map"]
)

partners = await RegIDORM.get_partner_by_reg_id(
id_type_config["g2p_id_type"], res.sub
id_type_config["g2p_id_type"], mapped_res.get("user_id")
)
if not partners:
raise UnauthorizedError(
Expand Down
2 changes: 2 additions & 0 deletions src/openg2p_portal_api/models/orm/auth_oauth_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AuthOauthProviderORM(BaseORMModel):
jwt_assertion_aud: Mapped[Optional[str]] = mapped_column()

scope: Mapped[Optional[str]] = mapped_column()
enable_pkce: Mapped[Optional[str]] = mapped_column()
code_verifier: Mapped[Optional[str]] = mapped_column()
date_format: Mapped[Optional[str]] = mapped_column()
company_id: Mapped[Optional[int]] = mapped_column()
Expand Down Expand Up @@ -154,6 +155,7 @@ def map_auth_provider_to_login_provider(self) -> LoginProvider:
response_type=response_type,
redirect_uri=self.g2p_portal_oauth_callback_url or "",
scope=self.scope,
enable_pkce=self.enable_pkce,
code_verifier=self.code_verifier,
extra_authorize_parameters=orjson.loads(
self.extra_authorize_params or "{}"
Expand Down
11 changes: 6 additions & 5 deletions src/openg2p_portal_api/services/partner_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ async def check_and_create_partner(
message="Invalid Auth Provider Configuration. ID Type not configured."
)

validation = AuthOauthProviderORM.map_validation_response(
validation, id_type_config["token_map"]
)
reg_id_res = await RegIDORM.get_partner_by_reg_id(
id_type_config["g2p_id_type"], validation["sub"]
id_type_config["g2p_id_type"], validation["user_id"]
)

if not reg_id_res:
id_value = validation["sub"]
validation = AuthOauthProviderORM.map_validation_response(
validation, id_type_config["token_map"]
)
id_value = validation["user_id"]

name = validation.pop("name", "")
partner_dict = {
"given_name": name.split(" ")[0],
Expand Down

0 comments on commit 6d3c652

Please sign in to comment.