Skip to content

Instantly share code, notes, and snippets.

@hersoncruz
Last active April 7, 2021 21:39
Show Gist options
  • Save hersoncruz/2b14dba094c86cff725d852933e52313 to your computer and use it in GitHub Desktop.
Save hersoncruz/2b14dba094c86cff725d852933e52313 to your computer and use it in GitHub Desktop.
auth_token client example
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
import crypt
import time
def index(request):
return HttpResponse("<a href='/sso/go/'>Go to LMS</a>")
def go(request):
secret_salt = 'AUTH_TOKEN_SALT'
timestamp = str(time.time())
user = 'USERNAME'
email = 'user@email.com'
newuser = str(1)
cohortname = '99999'
fn = 'FIRST_NAME'
ln = 'LAST_NAME'
city = 'CITY'
country = 'COUNTRY'
lmsurl = 'http://example.com'
payload = timestamp + user + email
token = crypt.crypt(payload, secret_salt)
url = lmsurl + '/auth/token/index.php'
sso_url = url + '?user=' + user + '&token=' + token + '&timestamp=' + timestamp + '&email=' + email + '&newuser=' + newuser + '&cohortname=' + cohortname + '&fn=' + fn + '&ln=' + ln + '&city=' + city + '&country=' + country
return HttpResponseRedirect(sso_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment