Don't hardcode OAuth2 parameters

This commit is contained in:
Yohann D'ANELLO 2021-11-14 15:17:55 +01:00
parent cdcb743b55
commit fe55a2a5ea
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
3 changed files with 24 additions and 15 deletions

View File

@ -167,22 +167,26 @@ PAGINATION_NUMBER = 25
AUTH_USER_MODEL = 'users.User' AUTH_USER_MODEL = 'users.User'
# AUTHLIB CLIENTS NOTE_KFET_URL = 'https://note.crans.org'
AUTHLIB_OAUTH_CLIENTS = { NOTE_KFET_CLIENT_ID = 'CHANGE_ME'
'notekfet': { NOTE_KFET_CLIENT_SECRET = 'CHANGE_ME'
'client_id': 'qtElmOUj67YNvSZjA5l70ITUMxd3NJ9kksBsK5e9', NOTE_KFET_SCOPES = '1_1 2_1 48_1'
'client_secret': 'SwF909sLIeU5GhruXsFzKfdBhFNgs8nvkVpFKgP4pIQ80BmLLlf3ZkMoNL7Cpox6Ke3MXNWGswTtbKkM8AiB9v6pys8PNfYH0MDFWAi3tnffjwaMQBzRFhjx20qb6S4W',
'access_token_url': 'https://note-dev.crans.org/o/token/',
'refresh_token_url': 'https://note-dev.crans.org/o/token/',
'authorize_url': 'https://note-dev.crans.org/o/authorize/',
'userinfo_endpoint': 'https://note-dev.crans.org/api/me/',
'client_kwargs': {
'scope': '1_1 2_1 48_1',
}
}
}
try: try:
from .settings_local import * from .settings_local import *
except ImportError: except ImportError:
pass pass
AUTHLIB_OAUTH_CLIENTS = {
'notekfet': {
'client_id': f'{NOTE_KFET_CLIENT_ID}',
'client_secret': f'{NOTE_KFET_CLIENT_SECRET}',
'access_token_url': f'{NOTE_KFET_URL}/o/token/',
'refresh_token_url': f'{NOTE_KFET_URL}/o/token/',
'authorize_url': f'{NOTE_KFET_URL}/o/authorize/',
'userinfo_endpoint': f'{NOTE_KFET_URL}/api/me/',
'client_kwargs': {
'scope': NOTE_KFET_SCOPES,
}
}
}

View File

@ -40,3 +40,8 @@ DATABASES = {
'PORT': '', 'PORT': '',
} }
} }
NOTE_KFET_URL = 'https://note.crans.org'
NOTE_KFET_CLIENT_ID = 'CHANGE_ME'
NOTE_KFET_CLIENT_SECRET = 'CHANGE_ME'
NOTE_KFET_SCOPES = '1_1 2_1 48_1'

View File

@ -178,7 +178,7 @@ class AccessToken(models.Model):
Extract information about the Note Kfet API by using the current Extract information about the Note Kfet API by using the current
access token. access token.
""" """
data = requests.get('https://note-dev.crans.org/api/me/', data = requests.get(f'{settings.NOTE_KFET_URL}/api/me/',
headers=self.auth_header()).json() headers=self.auth_header()).json()
username = data['username'] username = data['username']
email = data['email'] email = data['email']