Skip to content

Commit

Permalink
Merge pull request #1793 from SciPhi-AI/feature/add-oauth-callback-an…
Browse files Browse the repository at this point in the history
…d-fix-event-stream

up
  • Loading branch information
emrgnt-cmplxty authored Jan 10, 2025
2 parents 5ee250b + e2bb519 commit badb168
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 481 deletions.
2 changes: 1 addition & 1 deletion js/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r2r-js",
"version": "0.4.12",
"version": "0.4.13",
"description": "",
"main": "dist/index.js",
"browser": "dist/index.browser.js",
Expand Down
20 changes: 20 additions & 0 deletions js/sdk/src/v3/clients/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,24 @@ export class UsersClient {
async oauthGithubAuthorize(): Promise<{ redirect_url: string }> {
return this.client.makeRequest("GET", "users/oauth/github/authorize");
}

@feature("users.oauthGoogleCallback")
async oauthGoogleCallback(options: { code: string; state: string }): Promise<any> {
return this.client.makeRequest("POST", "users/oauth/google/callback", {
params: {
code: options.code,
state: options.state,
},
});
}

@feature("users.oauthGithubCallback")
async oauthGithubCallback(options: { code: string; state: string }): Promise<any> {
return this.client.makeRequest("POST", "users/oauth/github/callback", {
params: {
code: options.code,
state: options.state,
},
});
}
}
4 changes: 2 additions & 2 deletions py/core/main/api/v3/retrieval_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ async def stream_generator():
return

return StreamingResponse(
stream_generator(), media_type="application/json"
stream_generator(), media_type="text/event-stream"
) # type: ignore
else:
return response
Expand Down Expand Up @@ -673,7 +673,7 @@ async def stream_generator():
return

return StreamingResponse(
stream_generator(), media_type="application/json"
stream_generator(), media_type="text/event-stream"
) # type: ignore
else:
return response
Expand Down
8 changes: 4 additions & 4 deletions py/core/main/api/v3/users_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def validate_password(password: str) -> bool:

# if not validate_password(password):
# raise R2RException(
# status_code=400,
# message=f"Password must be at least 10 characters long and contain at least one uppercase letter, one lowercase letter, one digit, and one special character from '!@#$%^&*'.",
# f"Password must be at least 10 characters long and contain at least one uppercase letter, one lowercase letter, one digit, and one special character from '!@#$%^&*'.",
# 400,
# )

registration_response = await self.services.auth.register(
Expand Down Expand Up @@ -1790,7 +1790,7 @@ async def google_authorize():

@self.router.get("/users/oauth/google/callback")
async def google_callback(
request: Request, code: str = Query(...), state: str = Query(...)
code: str = Query(...), state: str = Query(...)
):
"""
Google's callback that will receive the `code` and `state`.
Expand All @@ -1807,7 +1807,6 @@ async def google_callback(
"grant_type": "authorization_code",
},
).json()

if "error" in token_data:
raise HTTPException(
status_code=400,
Expand Down Expand Up @@ -1839,6 +1838,7 @@ async def google_callback(
oauth_id=google_id,
email=email,
)
print("token_response = ", token_response)

# 4. Return tokens or redirect to your front-end
# Some people store tokens in a cookie or redirect to a front-end route passing them as a query param.
Expand Down
Loading

0 comments on commit badb168

Please sign in to comment.