I am creating a custom provider to get oauth2 tokens from another internal project, the process is almost fine, but I get an error 403 forbiddenwhen the browser returns my project with this URL:
http://localhost:8001/account/connect/login/callback/?state=Nngd5Gu3JnB4&code=Rqqg91oEwQKDsvSyzZ8Az5fEeHGaEe
here is view.py in my custom provider:
import requests
from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter, OAuth2LoginView, OAuth2CallbackView)
from .provider import ConnectProvider
class ConnectOAuth2Adapter(OAuth2Adapter):
provider_id = ConnectProvider.id
access_token_url = 'http://localhost:8000/o/token/'
authorize_url = 'http://localhost:8000/o/authorize/'
profile_url = 'http://localhost:8000/api/account/'
def complete_login(self, request, app, token, **kwargs):
_token = {'access_token':token.token}
resp = requests.get(self.profile_url, params={'access_token': token.token, 'alt': 'json'})
extra_data = resp.json()
login = self.get_provider().sociallogin_from_response(request, extra_data)
return login
oauth2_login = OAuth2LoginView.adapter_view(GoConnectOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(GoConnectOAuth2Adapter)
source
share