Ejemplo n.º 1
0
 def authenticate(self, access, auth_token):
     # Ensure that the tokens are valid for this provider
     # Nasty hack to ensure django.contrib.auth.authenticate() works
     if access.service != "twitter":
         raise TypeError
     # Get the user from Twitter
     auth = tweepy.OAuthHandler(access.key, access.secret)
     auth.set_access_token(auth_token.key, auth_token.secret)
     api = tweepy.API(auth)
     profile = api.me()
     # Match it with a django user
     user = access.lookup_user(identifier=profile.id)
     if not user:
         # Create a new user
         # We need to fudge the name in
         if profile.name:
             first_name = profile.name.split()[0]
             try:
                 last_name = profile.name.split()[1]
             except:
                 last_name = ""
         else:
             first_name = last_name = ""
         user = create_django_user(first_name=first_name,
                             last_name=last_name)
     # Persist the association
     access.persist(user=user, token=auth_token,
                     identifier=profile.id)
     return user
Ejemplo n.º 2
0
 def authenticate(self, access, auth_token):
     # Ensure that the tokens are valid for this provider
     # Nasty hack to ensure django.contrib.auth.authenticate() works
     if access.service != "linkedin":
         raise TypeError
     # Get the user from Linkedin
     api = linkedin.LinkedIn(access.key, access.secret, "")
     api.access_token, api.access_token_secret = auth_token.key, auth_token.secret
     profile = api.GetProfile(None,None,'id','first-name','last-name')
     # Match it with a django user
     user = access.lookup_user(identifier=profile.id)
     if not user:
         user = create_django_user(first_name=profile.first_name,
                             last_name=profile.last_name)
     # Persist the association
     access.persist(user=user, token=auth_token,
                 identifier=profile.id)
     return user
Ejemplo n.º 3
0
 def authenticate(self, access, auth_token):
     # Ensure that the tokens are valid for this provider
     # Nasty hack to ensure django.contrib.auth.authenticate() works
     if access.service != "facebook":
         raise TypeError
     # Get the user from facebook
     graph = facebook.GraphAPI(auth_token.token)
     profile = graph.get_object("me")
     # Match it with a django user
     user = access.lookup_user(identifier=profile['id'])
     if not user:
         # Create a new user
         user = create_django_user(first_name=profile['first_name'],
                             last_name=profile['last_name'])
     # Persist the association
     access.persist(user=user, token=auth_token,
                     identifier=profile['id'])
     return user