Example #1
0
    def callback(handler, settings):
        """handle the callback from an oauth provider"""
        """this is always called "statically" from OAuthHandler"""
        # we came from a callback and have our oauth_request_token
        oauth_request_token = handler.get_argument('oauth_request_token')

        # if succesfull in getting token, get some about me info
        user = find_user_by_oauth_request_token(oauth_request_token)

        logging.debug("facebook callback: %s" % oauth_request_token)

        url = settings['ACCESS_TOKEN_REQUEST_URL']
        query_params = {
            'client_id': settings['APP_ID'],
            'redirect_uri': settings['REDIRECT_URL'] +
            "?oauth_request_token=" + oauth_request_token,
            'client_secret': settings['APP_SECRET'],
            'code': handler.get_argument('code')
        }

        kv_pairs = ChatifyOAuth2Handler._request(handler, "POST", settings,
                                                 url, query_params, user)

        if 'access_token' in kv_pairs:
            access_token = kv_pairs['access_token']
            logging.debug("access_token %s" % access_token)
            # get a little more data about the user (me query)

            kvs = ChatifyOAuthHandler.get_user_info(handler, settings, user,
                                                    access_token)

            kv_pairs.update(kvs)

            oauth_data = json.dumps(kv_pairs)

            # we should store this data now
            if user == None:
                user = User(username=handler.username,
                            nickname=kv_pairs['username'],
                            current_oauth_provider=settings['PROVIDER_NAME'],
                            oauth_data=oauth_data)
            else:
                user.nickname = kv_pairs['username']
                user.oauth_id = kv_pairs['id']
                user.current_oauth_provider = settings['PROVIDER_NAME']
                user.oauth_data = oauth_data

            logging.debug("oauth_data: %s" % oauth_data)

            # adding an existing key just replaces it
            add_user(user)

            return handler.redirect("/oauth/" + settings['PROVIDER_NAME'] +
                                    "/loggedin")
        else:
            handler.set_status(403)
            handler.add_to_payload('messages', "Not Authenticated")

        return handler.render()
Example #2
0
    def callback(handler, settings):
        """handle the callback from an oauth provider"""
        """this is always called "statically" from OAuthHandler"""
        # we came from a callback and have our oauth_request_token
        oauth_request_token = handler.get_argument('oauth_request_token')

        # if succesfull in getting token, get some about me info
        user = find_user_by_oauth_request_token(oauth_request_token)
        
        logging.debug( "facebook callback: %s" % oauth_request_token );
        
        url = settings['ACCESS_TOKEN_REQUEST_URL']
        query_params = { 
            'client_id': settings['APP_ID'],
            'redirect_uri': settings['REDIRECT_URL'] + "?oauth_request_token=" + oauth_request_token,
            'client_secret': settings['APP_SECRET'],
            'code': handler.get_argument('code')
        }
        
        kv_pairs = ChatifyOAuth2Handler._request(handler, "POST", settings, url, query_params, user)


        if 'access_token' in kv_pairs:
            access_token = kv_pairs['access_token']
            logging.debug( "access_token %s" % access_token );
            # get a little more data about the user (me query)

            kvs = ChatifyOAuthHandler.get_user_info(handler, settings, user, access_token)

            kv_pairs.update(kvs)

            oauth_data = json.dumps(kv_pairs)

            # we should store this data now
            if user == None:
                user = User(username=handler.username, nickname=kv_pairs['username'], current_oauth_provider=settings['PROVIDER_NAME'], oauth_data=oauth_data)
            else:
                user.nickname = kv_pairs['username']
                user.oauth_id = kv_pairs['id']
                user.current_oauth_provider = settings['PROVIDER_NAME']
                user.oauth_data = oauth_data

            logging.debug( "oauth_data: %s" % oauth_data );

            # adding an existing key just replaces it
            add_user(user)

            return handler.redirect("/oauth/" + settings['PROVIDER_NAME'] + "/loggedin")
        else:
            handler.set_status(403)
            handler.add_to_payload('messages', "Not Authenticated")

        return handler.render()
Example #3
0
    def get(self, settings):
        # we are in development, fake it
        logging.debug( "facebook faking it" );
        user = find_user_by_username(self.username)
        oauth_data = ENVIRONMENT['TEST_OAUTH_DATA']
        # we should store this data now
        if user == None:
            user = User(username=self.username, nickname=oauth_data['username'], current_oauth_provider='facebook', oauth_data=json.dumps(oauth_data))
        else:
            user.nickname = oauth_data['username']
            user.current_oauth_provider = 'facebook'
            user.oauth_data = json.dumps(oauth_data)
        
        # adding an existing key just replaces it
        add_user(user)

        return self.redirect("/oauth/facebook/loggedin")
Example #4
0
    def redirector(handler, settings):
        """gets the token and redirects the user to the oauth login page """
        """this is always called "statically" from OAuthHandler"""

        try:
            url = settings['REQUEST_TOKEN_URL']
            oauth_callback = settings['CALLBACK_URL']

            logging.debug("oauth_callback: %s" % oauth_callback)

            query_params = {'oauth_callback': oauth_callback}

            kv_pairs = ChatifyOAuth1aHandler._request(handler, 'POST',
                                                      settings, url,
                                                      query_params, None)

            # save our data
            if 'oauth_token' in kv_pairs:
                oauth_token = kv_pairs['oauth_token']

                user = find_user_by_username(handler.username)
                logging.debug("oauth_token: %s" % oauth_token)
                if user == None:
                    user = User(
                        username=handler.username,
                        nickname=handler.username,
                        current_oauth_provider=settings['PROVIDER_NAME'],
                        oauth_data=json.dumps(kv_pairs))
                else:
                    user.current_oauth_provider = settings['PROVIDER_NAME']
                    user.oauth_data = json.dumps(kv_pairs)

                add_user(user)
                add_oauth_request_token(oauth_token, user.username)

                return handler.redirect(settings['AUTHORIZE_URL'] +
                                        '?oauth_token=' +
                                        kv_pairs['oauth_token'])

        except Exception:
            raise

        # we shouldn't get here
        handler.add_to_payload('message', 'an unknown error occured')

        return handler.render()
Example #5
0
    def redirector(handler, settings):
        """handle the redirect to an oauth provider"""
        """this is always called "statically" from OAuthHandler"""
        oauth_request_token = handler.username

        user = find_user_by_username(handler.username)
        if user == None:
            user = User(username=handler.username, nickname=handler.username, current_oauth_provider=settings['PROVIDER_NAME'])
        else:
            user.current_oauth_provider = settings['PROVIDER_NAME']

        add_user(user)
        add_oauth_request_token( oauth_request_token, user.username )

        url = "%s?client_id=%s&scope=%s&display=popup&redirect_uri=%s" % (settings['REQUEST_URL'], settings['APP_ID'], settings['SCOPE'], settings['REDIRECT_URL'] + "?oauth_request_token=" + oauth_request_token)

        # send user to facebook login
        logging.debug( settings['PROVIDER_NAME'] + " url %s" % url );
        return handler.redirect(url)
Example #6
0
    def get(self, settings):
        # we are in development, fake it
        logging.debug("facebook faking it")
        user = find_user_by_username(self.username)
        oauth_data = ENVIRONMENT['TEST_OAUTH_DATA']
        # we should store this data now
        if user == None:
            user = User(username=self.username,
                        nickname=oauth_data['username'],
                        current_oauth_provider='facebook',
                        oauth_data=json.dumps(oauth_data))
        else:
            user.nickname = oauth_data['username']
            user.current_oauth_provider = 'facebook'
            user.oauth_data = json.dumps(oauth_data)

        # adding an existing key just replaces it
        add_user(user)

        return self.redirect("/oauth/facebook/loggedin")
Example #7
0
    def redirector(handler, settings):
        """gets the token and redirects the user to the oauth login page """
        """this is always called "statically" from OAuthHandler"""

        try:
            url = settings['REQUEST_TOKEN_URL']
            oauth_callback = settings['CALLBACK_URL']
            
            logging.debug("oauth_callback: %s" % oauth_callback);

            query_params = {
                'oauth_callback': oauth_callback
            }

            kv_pairs = ChatifyOAuth1aHandler._request(handler, 'POST', settings, url, query_params, None)
    
            # save our data
            if 'oauth_token' in kv_pairs:
                oauth_token = kv_pairs['oauth_token']
    
                user = find_user_by_username(handler.username)
                logging.debug( "oauth_token: %s" % oauth_token );
                if user == None:
                    user = User(username=handler.username, nickname=handler.username, current_oauth_provider=settings['PROVIDER_NAME'], oauth_data=json.dumps(kv_pairs))
                else:
                    user.current_oauth_provider = settings['PROVIDER_NAME']
                    user.oauth_data = json.dumps(kv_pairs)


                add_user(user)
                add_oauth_request_token( oauth_token, user.username )

                return handler.redirect(settings['AUTHORIZE_URL'] + '?oauth_token=' + kv_pairs['oauth_token'])

        except Exception:
            raise

        # we shouldn't get here
        handler.add_to_payload('message', 'an unknown error occured')

        return handler.render()
Example #8
0
    def redirector(handler, settings):
        """handle the redirect to an oauth provider"""
        """this is always called "statically" from OAuthHandler"""
        oauth_request_token = handler.username

        user = find_user_by_username(handler.username)
        if user == None:
            user = User(username=handler.username,
                        nickname=handler.username,
                        current_oauth_provider=settings['PROVIDER_NAME'])
        else:
            user.current_oauth_provider = settings['PROVIDER_NAME']

        add_user(user)
        add_oauth_request_token(oauth_request_token, user.username)

        url = "%s?client_id=%s&scope=%s&display=popup&redirect_uri=%s" % (
            settings['REQUEST_URL'], settings['APP_ID'], settings['SCOPE'],
            settings['REDIRECT_URL'] + "?oauth_request_token=" +
            oauth_request_token)

        # send user to facebook login
        logging.debug(settings['PROVIDER_NAME'] + " url %s" % url)
        return handler.redirect(url)