def get_authorization_url(self, scopes, state_token=None): """Generates authorization url using scopes specified where user is redirected to :param scopes: Scopes for OAuth/OpenId flow :type scopes: list of enum, `intuitlib.enums.Scopes` :param state_token: CSRF token, defaults to None :return: Authorization url """ state = state_token or self.state_token if state is None: state = generate_token() self.state_token = state url_params = { 'client_id': self.client_id, 'response_type': 'code', 'scope': scopes_to_string(scopes), 'redirect_uri': self.redirect_uri, 'state': self.state_token } return '?'.join([self.auth_endpoint, urlencode(url_params)])
def test_generate_token(self): token = generate_token() assert len(token) == 30