Skip to content

Commit 74a702e

Browse files
committed
GH-9: Implement a data standardizer for converting fields to the common interface
1 parent 72b0a80 commit 74a702e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/fastapi_oauth2/core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async def get_token_data(self, request: Request) -> Optional[Dict[str, Any]]:
109109
async with httpx.AsyncClient() as session:
110110
response = await session.post(token_url, headers=headers, content=content, auth=auth)
111111
token = self.oauth_client.parse_request_body_response(json.dumps(response.json()))
112-
data = self.backend.user_data(token.get("access_token"))
112+
data = self.standardize(self.backend.user_data(token.get("access_token")))
113113

114114
return {**data, "scope": self.scope}
115115

@@ -125,3 +125,8 @@ async def token_redirect(self, request: Request) -> RedirectResponse:
125125
httponly=request.auth.http,
126126
)
127127
return response
128+
129+
def standardize(self, data: Dict[str, Any]) -> Dict[str, Any]:
130+
data["identity"] = "%s:%s" % (self.provider, data.get("id"))
131+
data["display_name"] = data.get("name")
132+
return data

0 commit comments

Comments
 (0)