def _verify_query()

in uber_rides/auth.py [0:0]


    def _verify_query(self, query_params):
        """Verify response from the Uber Auth server.

        Parameters
            query_params (dict)
                Dictionary of query parameters attached to your redirect URL
                after user approved your app and was redirected.

        Returns
            authorization_code (str)
                Code received when user grants your app access. Use this code
                to request an access token.

        Raises
            UberIllegalState (ApiError)
                Thrown if the redirect URL was missing parameters or if the
                given parameters were not valid.
        """
        error_message = None

        if self.state_token is not False:
            # Check CSRF State Token against state token from GET request
            received_state_token = query_params.get('state')
            if received_state_token is None:
                error_message = 'Bad Request. Missing state parameter.'
                raise UberIllegalState(error_message)

            if self.state_token != received_state_token:
                error_message = 'CSRF Error. Expected {}, got {}'
                error_message = error_message.format(
                    self.state_token,
                    received_state_token,
                )
                raise UberIllegalState(error_message)

        # Verify either 'code' or 'error' parameter exists
        error = query_params.get('error')
        authorization_code = query_params.get(auth.CODE_RESPONSE_TYPE)

        if error and authorization_code:
            error_message = (
                'Code and Error query params code and error '
                'can not both be set.'
            )
            raise UberIllegalState(error_message)

        if error is None and authorization_code is None:
            error_message = 'Neither query parameter code or error is set.'
            raise UberIllegalState(error_message)

        if error:
            raise UberIllegalState(error)

        return authorization_code