コード例 #1
0
    def test_get_scopes(self):
        # Test fetching scopes of a valid token
        oauth_token = db_oauth_token.create(
            client_id=self.oauth_client["client_id"],
            access_token="Test Access Token",
            refresh_token="Test Refresh Token",
            expires=datetime.now() + timedelta(seconds=200),
            user_id=self.user.id,
            scopes="Test Scopes",
        )
        self.assertIn("Test", db_oauth_token.get_scopes(oauth_token["id"]))
        # Test fetching scopes of a token that does not exist
        db_oauth_token.delete(client_id=self.oauth_client["client_id"],
                              refresh_token="Test Refresh Token")
        with self.assertRaises(db_exceptions.NoDataFoundException):
            db_oauth_token.get_scopes(oauth_token["id"])

        # Test fetching scopes of token with no scopes
        oauth_token = db_oauth_token.create(
            client_id=self.oauth_client["client_id"],
            access_token="Test Access Token",
            refresh_token="Test Refresh Token",
            expires=datetime.now() + timedelta(seconds=200),
            user_id=self.user.id,
            scopes=None,
        )
        self.assertEqual([], db_oauth_token.get_scopes(oauth_token["id"]))
コード例 #2
0
    def test_get_scopes(self):
        # Test fetching scopes of a valid token
        oauth_token = db_oauth_token.create(
            client_id=self.oauth_client["client_id"],
            access_token="Test Access Token",
            refresh_token="Test Refresh Token",
            expires=datetime.now() + timedelta(seconds=200),
            user_id=self.user.id,
            scopes="Test Scopes",
        )
        self.assertIn("Test", db_oauth_token.get_scopes(oauth_token["id"]))
        # Test fetching scopes of a token that does not exist
        db_oauth_token.delete(client_id=self.oauth_client["client_id"], refresh_token="Test Refresh Token")
        with self.assertRaises(db_exceptions.NoDataFoundException):
            db_oauth_token.get_scopes(oauth_token["id"])

        # Test fetching scopes of token with no scopes
        oauth_token = db_oauth_token.create(
            client_id=self.oauth_client["client_id"],
            access_token="Test Access Token",
            refresh_token="Test Refresh Token",
            expires=datetime.now() + timedelta(seconds=200),
            user_id=self.user.id,
            scopes=None,
        )
        self.assertEqual([], db_oauth_token.get_scopes(oauth_token["id"]))
コード例 #3
0
 def test_delete(self):
     db_oauth_token.create(
         client_id=self.oauth_client["client_id"],
         access_token="Test Access Token",
         refresh_token="Test Refresh Token",
         expires=datetime.now() + timedelta(seconds=200),
         user_id=self.user.id,
         scopes=None,
     )
     self.assertEqual(len(db_oauth_token.list_tokens(client_id=self.oauth_client["client_id"])), 1)
     db_oauth_token.delete(client_id=self.oauth_client["client_id"], refresh_token="Test Refresh Token")
     self.assertEqual(len(db_oauth_token.list_tokens(client_id=self.oauth_client["client_id"])), 0)
コード例 #4
0
 def test_delete(self):
     db_oauth_token.create(
         client_id=self.oauth_client["client_id"],
         access_token="Test Access Token",
         refresh_token="Test Refresh Token",
         expires=datetime.now() + timedelta(seconds=200),
         user_id=self.user.id,
         scopes=None,
     )
     self.assertEqual(
         len(
             db_oauth_token.list_tokens(
                 client_id=self.oauth_client["client_id"])), 1)
     db_oauth_token.delete(client_id=self.oauth_client["client_id"],
                           refresh_token="Test Refresh Token")
     self.assertEqual(
         len(
             db_oauth_token.list_tokens(
                 client_id=self.oauth_client["client_id"])), 0)
コード例 #5
0
 def discard_client_user_tokens(client_id, user_id):
     db_oauth_token.delete(client_id=client_id, user_id=user_id)
コード例 #6
0
 def discard_token(client_id, refresh_token):
     db_oauth_token.delete(client_id=client_id, refresh_token=refresh_token)
コード例 #7
0
def token_delete(client_id):
    db_oauth_token.delete(client_id=client_id, user_id=current_user.id)
    return redirect(url_for('.index'))