-
Notifications
You must be signed in to change notification settings - Fork 21
[ENG-5769] Oauth 1.0a integration #78
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
Changes from 6 commits
18f491f
d84a2c1
271cba0
f9ec901
8552be5
7db1040
5375b52
7c17719
6d2200f
1ebf5d4
da9b7e3
08f8d9a
05b1873
63d76db
2541c24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from addon_toolkit.interfaces.storage import StorageAddonImp | ||
|
|
||
|
|
||
| class ZoteroOrgCitationImp(StorageAddonImp): | ||
| pass | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,8 +95,14 @@ def create(self, validated_data): | |
| authorized_account.initiate_oauth2_flow( | ||
| validated_data.get("authorized_scopes") | ||
| ) | ||
| elif external_service.credentials_format is CredentialsFormats.OAUTH1A: | ||
| authorized_account.initiate_oauth1_flow() | ||
| self.context["request"].session[ | ||
| "oauth1a_account_id" | ||
| ] = authorized_account.pk | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to store the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't anything in payload which'd allow for is to identify it, I don't like this approach too, but I don't have any better ideas
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the callback request includes the same temporary token received when initiating oauth1 -- could add a model to hold oauth1 temporary state (parallel (edit: nevermind -- i think that's true in specs but not for zotero, oh well) |
||
| else: | ||
| authorized_account.credentials = validated_data["credentials"] | ||
|
|
||
| try: | ||
| authorized_account.save() | ||
| except ModelValidationError as e: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,27 @@ | ||
| from enum import Enum | ||
| from enum import ( | ||
| Enum, | ||
| unique, | ||
| ) | ||
|
|
||
| from addon_toolkit import credentials | ||
|
|
||
|
|
||
| @unique | ||
| class CredentialsFormats(Enum): | ||
| UNSPECIFIED = 0 | ||
| OAUTH2 = 1 | ||
| ACCESS_KEY_SECRET_KEY = 2 | ||
| USERNAME_PASSWORD = 3 | ||
| PERSONAL_ACCESS_TOKEN = 4 | ||
| OAUTH1A = 5 | ||
|
|
||
| @property | ||
| def dataclass(self): | ||
| match self: | ||
| case CredentialsFormats.OAUTH2: | ||
| return credentials.AccessTokenCredentials | ||
| case CredentialsFormats.OAUTH1A: | ||
| return credentials.OAuth1TokenCredentials | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For Oauth 1a, it should still be
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are |
||
| case CredentialsFormats.ACCESS_KEY_SECRET_KEY: | ||
| return credentials.AccessKeySecretKeyCredentials | ||
| case CredentialsFormats.PERSONAL_ACCESS_TOKEN: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from . import utils | ||
| from .models import OAuth1ClientConfig | ||
|
|
||
|
|
||
| __all__ = ("OAuth1ClientConfig", "utils") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from django.db import models | ||
|
|
||
| from addon_service.common.base_model import AddonsServiceBaseModel | ||
|
|
||
|
|
||
| class OAuth1ClientConfig(AddonsServiceBaseModel): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there not an
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the record: we're storing the |
||
| """ | ||
| Model for storing attributes that are required for managing | ||
| OAuth1 credentials exchanges with an ExternalService on behalf | ||
| of a registered client (e.g. the OSF) | ||
| """ | ||
|
|
||
| # URI that allows to obtain temporary request token to proceed with user auth | ||
| request_token_url = models.URLField(null=False) | ||
| # URI to which user will be redirected to authenticate | ||
| auth_url = models.URLField(null=False) | ||
|
jwalz marked this conversation as resolved.
|
||
| # URI to obtain access token | ||
| access_token_url = models.URLField(null=False) | ||
|
|
||
| client_key = models.CharField(null=True) | ||
| client_secret = models.CharField(null=True) | ||
|
opaduchak marked this conversation as resolved.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, the client secret should be stored encrypted -- but since OAuth2ClientConfig is the same, maybe worth splitting that into another ticket? (...and i'm starting to reconsider the EncryptedDataclassModel abstract base, now that we have three potential uses for it...)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, storing any unencrypted credentials in the db, poses security risks
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, separate ticket. Need input from cloud eng/devops as to whether they want this in the database at all or if they'd prefer an approach like this one |
||
|
|
||
| class Meta: | ||
| verbose_name = "OAuth1 Client Config" | ||
| verbose_name_plural = "OAuth1 Client Configs" | ||
| app_label = "addon_service" | ||
|
|
||
| def __repr__(self): | ||
| return f'<{self.__class__.__qualname__}(pk="{self.pk}", auth_uri="{self.auth_url}, access_token_url="{self.access_token_url}", request_token_url="{self.request_token_url}", client_key="{self.client_key}")>' | ||
|
|
||
| __str__ = __repr__ | ||
Uh oh!
There was an error while loading. Please reload this page.