So I've been trying to learn how to authenticate users in my Django application with OAuth.
However, once I've followed the instructions in the "Python" part I got confused. I successfully logged in using my Ion account, but when I went to the admin page (localhost:8000/admin)
def login(request):
oauth = OAuth2Session("SsRYDH1iY6jqLO6rSVnF3A1NtYz4Y3fiO9qUMNAX", redirect_uri="http://127.0.0.1:8000/callback",scope=["read", "write"])
authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/")
return redirect(authorization_url)
def callback(request):
oauth = OAuth2Session("SsRYDH1iY6jqLO6rSVnF3A1NtYz4Y3fiO9qUMNAX", redirect_uri="http://127.0.0.1:8000/callback", scope=["read", "write"])
code = request.GET.get('code', None)
token = oauth.fetch_token("https://ion.tjhsst.edu/oauth/token/", code=code, client_secret="H78F4vUYd1uTtRSQcCWm0IrSesEhRAXNNh2JRe8KG0LyaJAPY2cPFhIQtKfzqKtMNk6vQxbuOAW2WfedjyNdJ4TLobwKh3NLfe2Am9NNL95T28XTPZWItLqRLKnJOdDu")
return render(request, 'index.html')
urls.py:
path(r'oauth/', views.login, name='login'),
path(r'callback/', views.callback, name='callback'),
settings.py:
INSTALLED_APPS = (
...
'users.apps.UsersConfig',
'ion_oauth',
)
How am I supposed to do this? I had already implemented an internal login/logout system through Django's forms, but I want to authenticate it through the provided servers. Thanks!