-
Notifications
You must be signed in to change notification settings - Fork 0
fix(auth): 🐛 Fix auth mechanism after testing and integration #5
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 3.12 | ||
| 3.13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package google.protobuf; | ||
|
|
||
| option go_package = "google.golang.org/protobuf/types/known/emptypb"; | ||
| option java_package = "com.google.protobuf"; | ||
| option java_outer_classname = "EmptyProto"; | ||
| option java_multiple_files = true; | ||
| option objc_class_prefix = "GPB"; | ||
| option csharp_namespace = "Google.Protobuf.WellKnownTypes"; | ||
| option cc_enable_arenas = true; | ||
|
|
||
| // A generic empty message that you can re-use to avoid defining duplicated | ||
| // empty messages in your APIs. A typical example is to use it as the request | ||
| // or the response type of an API method. For instance: | ||
| // | ||
| // service Foo { | ||
| // rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); | ||
| // } | ||
| // | ||
| message Empty {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from typing import Optional | ||
|
|
||
| from fastapi import HTTPException, Request, status | ||
| from fastapi.security import OAuth2PasswordBearer | ||
|
|
||
|
|
||
| class CustomOAuth2PasswordBearer(OAuth2PasswordBearer): | ||
| async def __call__(self, request: Request) -> Optional[str]: | ||
| token = request.cookies.get("access_token") | ||
| if not token: | ||
| if self.auto_error: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_401_UNAUTHORIZED, | ||
| detail="Not authenticated", | ||
| headers={"WWW-Authenticate": "Bearer"}, | ||
| ) | ||
| else: | ||
| return None | ||
| return token | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import asyncio | ||
|
|
||
| from mem_db_utils.asyncio import MemDBConnector | ||
| from redis import Redis | ||
|
|
||
| from tp_auth_serverside.config import Database | ||
|
|
||
| mem_connector = MemDBConnector(db=Database.login_redis_db) | ||
| mem_connector = MemDBConnector() | ||
|
|
||
| login_db: Redis = mem_connector.connect(db=Database.login_redis_db, decode_response=True) | ||
| refresh_restrict_db: Redis = mem_connector.connect(db=Database.refresh_restrict_db, decode_response=True) | ||
| login_db: Redis = asyncio.run(mem_connector.connect(db=Database.login_redis_db, decode_response=True)) | ||
| refresh_restrict_db: Redis = asyncio.run(mem_connector.connect(db=Database.refresh_restrict_db, decode_response=True)) | ||
|
faizanazim11 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,15 @@ | ||
| import logging | ||
|
|
||
| from tp_auth_serverside.config import Secrets | ||
| from tp_auth_serverside.db.memorydb import refresh_restrict_db | ||
|
|
||
|
|
||
| async def set_restrict_refresh(user_id: str, token: str) -> None: | ||
| logging.info(f"Setting refresh restrict for user_id: {user_id}, token: {token}") | ||
| await refresh_restrict_db.set(f"{user_id}__{token}", "restricted", ex=Secrets.refresh_restrict_minutes * 60) | ||
|
|
||
|
|
||
| async def is_refresh_restricted(user_id: str, token: str) -> bool: | ||
| return await refresh_restrict_db.exists(f"{user_id}__{token}") == 1 | ||
| result = await refresh_restrict_db.exists(f"{user_id}__{token}") | ||
| logging.info(f"Checking refresh restrict for user_id: {user_id}, token: {token}, exists: {result}") | ||
|
faizanazim11 marked this conversation as resolved.
|
||
| return result == 1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.