Beispiel #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()
Beispiel #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()
Beispiel #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")
Beispiel #4
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")