mirror of
https://github.com/Rushilwiz/chirper.git
synced 2025-04-10 23:40:18 -04:00
working
This commit is contained in:
parent
c8be363bf9
commit
7889cb0f3b
|
@ -1,6 +0,0 @@
|
|||
{% extends "blog/base.html" %}
|
||||
{% block content %}
|
||||
<div class="content-section">
|
||||
<a class="btn btn-primary btn-lg btn-block" href="#" role="button">Sign in with Ion</a>
|
||||
</div>
|
||||
{% endblock content %}
|
|
@ -3,5 +3,4 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path('', views.login, name='login'),
|
||||
path('callback/', views.callback),
|
||||
]
|
||||
|
|
|
@ -1,33 +1,30 @@
|
|||
from django.shortcuts import render, redirect
|
||||
from requests_oauthlib import OAuth2Session
|
||||
from oauthlib.oauth2 import TokenExpiredError
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
import json
|
||||
import requests
|
||||
|
||||
# Create your views here.
|
||||
|
||||
client_id = r'6p7HJlFCD8cnBNBEdgMsdULS5ph0jserw1xvWfxX'
|
||||
client_secret = r'E1e79KebxzAp0LBEtxcUg32b0qFP9Ap9Dxqkac6Qhci5AwXFhSfrbe7MtmGJUh6DDgxivJpGgFYNQgusfvoSraDAnsq3NnEET5DmxgfBBvvuYc2bwDq6KpeKIDQqFtwz'
|
||||
redirect_uri = 'http://localhost:8000/login/callback/'
|
||||
redirect_uri = 'http://localhost:8000/login/'
|
||||
token_url = 'https://ion.tjhsst.edu/oauth/authorize/'
|
||||
scope=["read","write"]
|
||||
|
||||
def login(request):
|
||||
client = requests.session()
|
||||
if request.method == "GET":
|
||||
code = request.GET.get('code')
|
||||
if code is not None:
|
||||
payload = {'grant_type':'authorization_code','code': code,'redirect_uri':redirect_uri,'client_id':client_id,'client_secret':client_secret, 'csrfmiddlewaretoken': request.GET.get("state")}
|
||||
token = requests.post("https://ion.tjhsst.edu/oauth/token/", data=payload)
|
||||
# profile = requests.post("https://ion.tjhsst.edu/api/profile", headers="Authorization: Bearer {token.access_token}")
|
||||
return redirect('/')
|
||||
|
||||
|
||||
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope)
|
||||
authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/")
|
||||
print(f'a_url: {authorization_url}')
|
||||
|
||||
return redirect(authorization_url)
|
||||
|
||||
# {'grant_type':'authorization_code','code':code,'redirect_uri':redirect_uri,'client_id':client_id,'client_secret':client_secret}
|
||||
|
||||
|
||||
def callback(request):
|
||||
return render(request, 'users/callback.html')
|
||||
code = fr"{request.GET.get('code')}"
|
||||
payload = {'grant_type':'authorization_code','code':code,'redirect_uri':redirect_uri,'client_id':client_id,'client_secret':client_secret}
|
||||
token = requests.post(token_url, data=payload)
|
||||
#print (code)
|
||||
#token = oauth.fetch_token(token_url=token_url, code=code, client_secret=client_secret)
|
||||
print(token)
|
||||
|
|
Loading…
Reference in New Issue
Block a user