base private accounts url
This commit is contained in:
parent
eb29cc2627
commit
5c352cf64c
2 changed files with 6 additions and 9 deletions
|
|
@ -97,7 +97,7 @@ class OAuthCode(models.Model):
|
||||||
|
|
||||||
def generate_login_url(self):
|
def generate_login_url(self):
|
||||||
redirect_uri = 'http://127.0.0.1:8000/users/login/callback/'
|
redirect_uri = 'http://127.0.0.1:8000/users/login/callback/'
|
||||||
url = f'{settings.BASE_OAUTH2_PROVIDER_URL}/oauth2/authorize/?response_type=code&code_challenge={self.generate_code_challenge()}&code_challenge_method=S256&client_id={settings.CLIENT_ID}&scope={settings.SCOPES}&state={self.uuid}&redirect_uri={self.redirect_uri}'
|
url = f'{settings.BASE_OAUTH2_PROVIDER_PUBLIC_URL}/authorize/?response_type=code&code_challenge={self.generate_code_challenge()}&code_challenge_method=S256&client_id={settings.CLIENT_ID}&scope={settings.SCOPES}&state={self.uuid}&redirect_uri={self.redirect_uri}'
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def validate_code(self, redirect_uri):
|
def validate_code(self, redirect_uri):
|
||||||
|
|
@ -113,6 +113,6 @@ class OAuthCode(models.Model):
|
||||||
"grant_type": "authorization_code"
|
"grant_type": "authorization_code"
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post(f'{settings.BASE_OAUTH2_PROVIDER_URL}/oauth2/token/', data=data, headers=headers)
|
response = requests.post(f'{settings.BASE_OAUTH2_PROVIDER_PRIVATE_URL}/token/', data=data, headers=headers)
|
||||||
|
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
@ -76,7 +76,9 @@ OAUTH2_PROVIDER_ID_TOKEN_MODEL = "gooyal_oauth2.IDToken"
|
||||||
OAUTH2_PROVIDER_GRANT_MODEL = "gooyal_oauth2.Grant"
|
OAUTH2_PROVIDER_GRANT_MODEL = "gooyal_oauth2.Grant"
|
||||||
OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL = "gooyal_oauth2.RefreshToken"
|
OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL = "gooyal_oauth2.RefreshToken"
|
||||||
|
|
||||||
BASE_OAUTH2_PROVIDER_URL = "https://accounts.gooyal.com"
|
BASE_OAUTH2_PROVIDER_PUBLIC_URL = config("BASE_OAUTH2_PROVIDER_PUBLIC_URL")
|
||||||
|
BASE_OAUTH2_PROVIDER_PRIVATE_URL = config("BASE_OAUTH2_PROVIDER_PRIVATE_URL")
|
||||||
|
|
||||||
CLIENT_ID = config('CLIENT_ID')
|
CLIENT_ID = config('CLIENT_ID')
|
||||||
CLIENT_SECRET = config('CLIENT_SECRET')
|
CLIENT_SECRET = config('CLIENT_SECRET')
|
||||||
SCOPES = config('SCOPES', default='')
|
SCOPES = config('SCOPES', default='')
|
||||||
|
|
@ -88,7 +90,7 @@ OAUTH2_PROVIDER = {
|
||||||
# 'groups': 'Access to your groups',
|
# 'groups': 'Access to your groups',
|
||||||
# 'introspection': 'Introspect token scope'},
|
# 'introspection': 'Introspect token scope'},
|
||||||
'OAUTH2_VALIDATOR_CLASS': 'apps.gooyal_oauth2.validators.OAuth2Validator',
|
'OAUTH2_VALIDATOR_CLASS': 'apps.gooyal_oauth2.validators.OAuth2Validator',
|
||||||
'RESOURCE_SERVER_INTROSPECTION_URL': BASE_OAUTH2_PROVIDER_URL + '/oauth2/introspect/',
|
'RESOURCE_SERVER_INTROSPECTION_URL': BASE_OAUTH2_PROVIDER_PRIVATE_URL + '/oauth2/introspect/',
|
||||||
# 'RESOURCE_SERVER_AUTH_TOKEN': '3yUqsWtwKYKHnfivFcJu', # OR this but not both:
|
# 'RESOURCE_SERVER_AUTH_TOKEN': '3yUqsWtwKYKHnfivFcJu', # OR this but not both:
|
||||||
'RESOURCE_SERVER_INTROSPECTION_CREDENTIALS': (CLIENT_ID, CLIENT_SECRET),
|
'RESOURCE_SERVER_INTROSPECTION_CREDENTIALS': (CLIENT_ID, CLIENT_SECRET),
|
||||||
}
|
}
|
||||||
|
|
@ -119,11 +121,6 @@ SPECTACULAR_SETTINGS = {
|
||||||
# OTHER SETTINGS
|
# OTHER SETTINGS
|
||||||
# Oauth2 related settings. used for example by django-oauth2-toolkit.
|
# Oauth2 related settings. used for example by django-oauth2-toolkit.
|
||||||
# https://spec.openapis.org/oas/v3.0.3#oauth-flows-object
|
# https://spec.openapis.org/oas/v3.0.3#oauth-flows-object
|
||||||
'OAUTH2_FLOWS': [],
|
|
||||||
'OAUTH2_AUTHORIZATION_URL': f'{BASE_OAUTH2_PROVIDER_URL}/oauth2/authorize/',
|
|
||||||
'OAUTH2_TOKEN_URL': f'{BASE_OAUTH2_PROVIDER_URL}/oauth2/token/',
|
|
||||||
'OAUTH2_REFRESH_URL': None,
|
|
||||||
'OAUTH2_SCOPES': None,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue