    def generate_state(self, next_url=None, **extra_state):
        """Generate a state string, given a next_url redirect target

        The state info is stored locally in self._oauth_states,
        and only the state id is returned for use in the oauth state field (cookie, redirect param)

        Parameters
        ----------
        next_url : str
            The URL of the page to redirect to on successful login.

        Returns
        -------
        state_id (str): The state string to be used as a cookie value.
        """
        state_id = secrets.token_urlsafe(16)
        state = {'next_url': next_url}
        if extra_state:
            state.update(extra_state)
        self._oauth_states[state_id] = state
        return state_id
Generate a state string, given a next_url redirect target

The state info is stored locally in self._oauth_states,
and only the state id is returned for use in the oauth state field (cookie, redirect param)

Parameters
----------
next_url : str
The URL of the page to redirect to on successful login.

Returns
-------
state_id (str): The state string to be used as a cookie value.
jupyterhub/services/auth.py