Login

Django plugin for LoginRadius

Author:
diegolis
Posted:
February 10, 2012
Language:
Python
Version:
1.3
Score:
0 (after 0 ratings)

Dependencies: urllib, simplejson

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import urllib
import simplejson

class LoginRadius:
    def __init__(self, request, api_secrete):
        self.is_authenticated = False
        if "token" in request.POST:
            validate_url = "http://hub.loginradius.com/userprofile.ashx?token=%s&apisecrete=%s" % (request.POST['token'], api_secrete)
            response = urllib.urlopen(validate_url)
            json_response = response.read()
            if json_response:
                self.user_profile=simplejson.loads(json_response)
                if "ID" in self.user_profile and self.user_profile["ID"]:
                    self.is_authenticated = True


"""
Example view:

from login import LoginRadius

def login_with_loginradius(request):
    login = LoginRadius(request, SECRET_KEY)
    if login.is_authenticated:
        profile = login.user_profile
        # profile is a dict with all the information retrieved by the provider
        ...
"""

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 11 months ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 1 week ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

Please login first before commenting.