mirror of
https://github.com/Rushilwiz/chirper.git
synced 2025-04-18 03:00: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 = [
|
urlpatterns = [
|
||||||
path('', views.login, name='login'),
|
path('', views.login, name='login'),
|
||||||
path('callback/', views.callback),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,33 +1,30 @@
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from requests_oauthlib import OAuth2Session
|
from requests_oauthlib import OAuth2Session
|
||||||
|
from oauthlib.oauth2 import TokenExpiredError
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
client_id = r'6p7HJlFCD8cnBNBEdgMsdULS5ph0jserw1xvWfxX'
|
client_id = r'6p7HJlFCD8cnBNBEdgMsdULS5ph0jserw1xvWfxX'
|
||||||
client_secret = r'E1e79KebxzAp0LBEtxcUg32b0qFP9Ap9Dxqkac6Qhci5AwXFhSfrbe7MtmGJUh6DDgxivJpGgFYNQgusfvoSraDAnsq3NnEET5DmxgfBBvvuYc2bwDq6KpeKIDQqFtwz'
|
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/'
|
token_url = 'https://ion.tjhsst.edu/oauth/authorize/'
|
||||||
scope=["read","write"]
|
scope=["read","write"]
|
||||||
|
|
||||||
def login(request):
|
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)
|
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope)
|
||||||
authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/")
|
authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/")
|
||||||
print(f'a_url: {authorization_url}')
|
print(f'a_url: {authorization_url}')
|
||||||
|
|
||||||
return redirect(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