| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from django.http import HttpRequest |
| 4 |
|
| 5 |
from allauth.socialaccount.providers.base import AuthAction, ProviderAccount |
| 6 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 7 |
from allauth.socialaccount.providers.ynab.views import YNABOAuth2Adapter |
| 8 |
|
| 9 |
|
| 10 |
class Scope: |
| 11 |
ACCESS = "read-only" |
| 12 |
|
| 13 |
|
| 14 |
class YNABAccount(ProviderAccount): |
| 15 |
pass |
| 16 |
|
| 17 |
|
| 18 |
class YNABProvider(OAuth2Provider): |
| 19 |
id = "ynab" |
| 20 |
name = "YNAB" |
| 21 |
account_class = YNABAccount |
| 22 |
oauth2_adapter_class = YNABOAuth2Adapter |
| 23 |
|
| 24 |
def get_default_scope(self): |
| 25 |
scope = [Scope.ACCESS] |
| 26 |
return scope |
| 27 |
|
| 28 |
def get_auth_params_from_request(self, request: HttpRequest, action): |
| 29 |
ret = super().get_auth_params_from_request(request, action) |
| 30 |
if action == AuthAction.REAUTHENTICATE: |
| 31 |
ret["prompt"] = "select_account consent" |
| 32 |
return ret |
| 33 |
|
| 34 |
def extract_uid(self, data): |
| 35 |
return str(data["data"]["user"]["id"]) |
| 36 |
|
| 37 |
|
| 38 |
provider_classes = [YNABProvider] |