Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue 2673] Users token stub endpoint #2885

Merged
merged 47 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8d7486e
add Schema for User/Token endpoint
babebe Nov 15, 2024
136dd01
add new user/token endpoint with static response
babebe Nov 15, 2024
50b2b75
Create ERD diagram and Update OpenAPI spec
nava-platform-bot Nov 15, 2024
ec38d8f
fix description
babebe Nov 15, 2024
d4468d0
merge main
babebe Nov 15, 2024
ac57712
Merge branch '2673/users-token-sub-endpoint' of https://github.com/HH…
babebe Nov 15, 2024
6cc4c37
Create ERD diagram and Update OpenAPI spec
nava-platform-bot Nov 15, 2024
f32b05a
user api blueprint
babebe Nov 18, 2024
352a79a
user routes with user/token endpoint
babebe Nov 18, 2024
e90139d
moved user endpoint
babebe Nov 18, 2024
ef9861d
moved user schemas
babebe Nov 18, 2024
c501111
user schemas
babebe Nov 18, 2024
6e83042
register user routes on blueprint
babebe Nov 18, 2024
db810fd
Merge branch '2673/users-token-sub-endpoint' of https://github.com/HH…
babebe Nov 18, 2024
cd15718
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov into…
babebe Nov 18, 2024
98aabd4
Create ERD diagram and Update OpenAPI spec
nava-platform-bot Nov 18, 2024
9ef31c0
rm versioning
babebe Nov 18, 2024
0b3e402
Merge branch '2673/users-token-sub-endpoint' of https://github.com/HH…
babebe Nov 18, 2024
625f366
fix import
babebe Nov 18, 2024
a95f46b
register user routes blueprint
babebe Nov 18, 2024
1f03377
fix naming
babebe Nov 18, 2024
528dfd1
Create ERD diagram and Update OpenAPI spec
nava-platform-bot Nov 18, 2024
4594b26
define param for swagger
babebe Nov 19, 2024
15d14b8
Create ERD diagram and Update OpenAPI spec
nava-platform-bot Nov 19, 2024
34624a2
unit test user/route
babebe Nov 19, 2024
4c90bfb
use SHARED_ALPHA_DESCRIPTION
babebe Nov 19, 2024
240614b
Create ERD diagram and Update OpenAPI spec
nava-platform-bot Nov 19, 2024
db30992
set auth_endpoint env variable
babebe Nov 20, 2024
4e45c18
validate response data
babebe Nov 20, 2024
45b249d
add header schema
babebe Nov 20, 2024
e3292ad
add blueprint header
babebe Nov 20, 2024
c0c643d
lint/format
babebe Nov 20, 2024
3fc08bf
Merge branch '2673/users-token-sub-endpoint' of https://github.com/HH…
babebe Nov 20, 2024
4f34b86
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov into…
babebe Nov 20, 2024
dee8882
Create ERD diagram and Update OpenAPI spec
nava-platform-bot Nov 20, 2024
fda2bfb
Set auth_endpoint env var
babebe Nov 20, 2024
d807154
Merge branch '2673/users-token-sub-endpoint' of https://github.com/HH…
babebe Nov 20, 2024
5c8320f
update AuthEndpointConfig
babebe Nov 20, 2024
6a1dd4d
add ENABLE_AUTH_ENDPOINT env var
babebe Nov 20, 2024
aceb260
update endpoint route
babebe Nov 21, 2024
d3bf43b
Create ERD diagram and Update OpenAPI spec
nava-platform-bot Nov 21, 2024
3f5934f
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov into…
babebe Nov 21, 2024
b81c3fe
Merge branch '2673/users-token-sub-endpoint' of https://github.com/HH…
babebe Nov 21, 2024
e623330
fix comment
babebe Nov 21, 2024
2b25ab7
rm docstring and response type
babebe Nov 21, 2024
4b35871
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov into…
babebe Nov 21, 2024
0433f6e
cleanup
babebe Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions api/openapi.generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ paths:
tags:
- Health
summary: Health
/v1/user/token:
post:
parameters: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/OpportunityUserTokenResponseV1'
description: Successful response
'401':
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
description: Authentication error
tags:
- Opportunity v1
summary: User Token
security:
- ApiKeyAuth: []
/v1/opportunities/search:
post:
parameters: []
Expand Down Expand Up @@ -350,6 +371,45 @@ components:
type: string
description: An internal tracking ID
example: 550e8400-e29b-41d4-a716-446655440000
UserV1:
type: object
properties:
user_id:
type: string
description: The internal ID of a user
example: 861a0148-cf2c-432b-b0b3-690016299ab1
email:
type: string
description: The email address returned from Oauth2 provider
example: [email protected]
external_user_type:
type: string
description: The Oauth2 provider through which a user was authenticated
example: login_gov
OpportunityUserTokenResponseV1:
type: object
properties:
message:
type: string
description: The message to return
example: Success
data:
description: The REST resource object
status_code:
type: integer
description: The HTTP status code
example: 200
token:
type: string
description: Internal token generated for a user
user:
type:
- object
allOf:
- $ref: '#/components/schemas/UserV1'
is_user_new:
type: boolean
description: Whether or not the user existed in our database
FundingInstrumentFilterV1:
type: object
properties:
Expand Down
27 changes: 26 additions & 1 deletion api/src/api/opportunities_v1/opportunity_routes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io
import logging

from flask import Response
from flask import Response, request

import src.adapters.db as db
import src.adapters.db.flask_db as flask_db
Expand Down Expand Up @@ -212,3 +212,28 @@ def opportunity_versions_get(db_session: db.Session, opportunity_id: int) -> res
data = get_opportunity_versions(db_session, opportunity_id)

return response.ApiResponse(message="Success", data=data)


@opportunity_blueprint.post("/user/token")
@opportunity_blueprint.output(opportunity_schemas.OpportunityUserTokenResponseV1Schema)
@opportunity_blueprint.auth_required(api_key_auth)
babebe marked this conversation as resolved.
Show resolved Hide resolved
def user_token() -> response.ApiResponse | Response:
logger.info("POST /v1/user/token")

header_token = request.headers.get("X-OAuth-login-gov")
if header_token:
data = {
"token": "the token goes here!",
"user": {
"user_id": "abc-...",
"email": "[email protected]",
"external_user_type": "login_gov",
},
"is_user_new": True,
}
return response.ApiResponse(message="Success", data=data)

message = "Missing X-OAuth-login-gov header"
logger.error(message)

return response.ApiResponse(message=message, status_code=400)
babebe marked this conversation as resolved.
Show resolved Hide resolved
36 changes: 36 additions & 0 deletions api/src/api/opportunities_v1/opportunity_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,39 @@ class OpportunitySearchResponseV1Schema(AbstractResponseSchema, PaginationMixinS
OpportunityFacetV1Schema(),
metadata={"description": "Counts of filter/facet values in the full response"},
)


class UserV1Schema(Schema):
user_id = fields.String(
metadata={
"description": "The internal ID of a user",
"example": "861a0148-cf2c-432b-b0b3-690016299ab1",
}
)
email = fields.String(
metadata={
"description": "The email address returned from Oauth2 provider",
"example": "[email protected]",
}
)
external_user_type = fields.String(
metadata={
babebe marked this conversation as resolved.
Show resolved Hide resolved
"description": "The Oauth2 provider through which a user was authenticated",
"example": "login_gov",
}
)


class OpportunityUserTokenResponseV1Schema(AbstractResponseSchema):
babebe marked this conversation as resolved.
Show resolved Hide resolved
token = fields.String(
metadata={
"description": "Internal token generated for a user",
}
)
user = fields.Nested(UserV1Schema())
is_user_new = fields.Boolean(
allow_none=False,
metadata={
"description": "Whether or not the user existed in our database",
},
)