-
Notifications
You must be signed in to change notification settings - Fork 34
feat: Implement Shotgrid authentication with username/password #48
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
Open
aviralgarg05
wants to merge
5
commits into
AcademySoftwareFoundation:main
Choose a base branch
from
aviralgarg05:feature/shotgrid-auth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0d78417
feat: Implement Shotgrid authentication with username/password
aviralgarg05 3f5130a
feat: Refactor `authenticate_user` to accept only username and passwo…
aviralgarg05 a8dc9d4
test: Update tests to match refactored auth logic and fix broken imports
aviralgarg05 3b04d3e
feat: Separate authentication logic into ShotgridAuthenticationProvid…
aviralgarg05 753cac9
Merge upstream/main and address PR #48 feedback
aviralgarg05 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
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,59 @@ | ||
| """ShotGrid authentication provider implementation.""" | ||
|
|
||
| import os | ||
| from typing import Any, Optional | ||
|
|
||
| from shotgun_api3 import Shotgun | ||
|
|
||
|
|
||
| class ShotgridAuthenticationProvider: | ||
| """Provider for ShotGrid authentication.""" | ||
|
|
||
| @staticmethod | ||
| def authenticate( | ||
| username: str, password: str, provider_url: Optional[str] = None | ||
| ) -> dict[str, Any]: | ||
| """Authenticate a user with ShotGrid and return session token and user info. | ||
|
|
||
| Args: | ||
| username: User login/username | ||
| password: User password | ||
| provider_url: Optional ShotGrid URL. If not provided, uses SHOTGRID_URL env var. | ||
|
|
||
| Returns: | ||
| Dictionary containing 'token' and 'email' | ||
|
|
||
| Raises: | ||
| ValueError: If authentication fails | ||
| """ | ||
| url = provider_url or os.getenv("SHOTGRID_URL") | ||
| if not url: | ||
| raise ValueError("SHOTGRID_URL not configured") | ||
|
|
||
| try: | ||
| # Initialize connection to verify credentials and get token | ||
| sg = Shotgun(url, login=username, password=password) | ||
| token = sg.get_session_token() | ||
|
|
||
| # We need to fetch the user details (email) | ||
| # We can use the same connection object 'sg' if it supports find/find_one after auth | ||
| # OR create a new connection with the token. | ||
| # Using the existing 'sg' instance is more efficient as it's already authenticated/connected (presumably). | ||
| # However, shotgun_api3 behaviour: 'sg' initialized with login/pass IS valid. | ||
|
|
||
| # Implementation note: We need to find the user by login to get the email. | ||
| user_data = sg.find_one( | ||
| "HumanUser", filters=[["login", "is", username]], fields=["email"] | ||
| ) | ||
|
|
||
| if not user_data: | ||
| raise ValueError(f"User not found: {username}") | ||
|
|
||
| email = user_data.get("email") | ||
| if not email: | ||
| raise ValueError("User has no email address configured") | ||
|
|
||
| return {"token": token, "email": email} | ||
|
|
||
| except Exception as e: | ||
| raise ValueError(f"Authentication failed: {str(e)}") |
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.
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.