-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support Auth0 OAuth2 * lint
- Loading branch information
Showing
3 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import logging | ||
import os | ||
import unittest | ||
from unittest.mock import MagicMock | ||
|
||
from flask import Flask | ||
from flask_appbuilder import AppBuilder, SQLA | ||
|
@@ -47,7 +48,22 @@ def setUp(self): | |
"AZURE_APPLICATION_ID/" | ||
"oauth2/authorize", | ||
}, | ||
} | ||
}, | ||
{ | ||
"name": "auth0", | ||
"icon": "fa-shield-halved", | ||
"token_key": "access_token", | ||
"remote_app": { | ||
"client_id": "AUTH0_KEY", | ||
"client_secret": "AUTH0_SECRET", | ||
"api_base_url": "https://AUTH0_DOMAIN/oauth2/v1/", | ||
"client_kwargs": {"scope": "openid profile email groups"}, | ||
"access_token_url": "https://AUTH0_DOMAIN/oauth/token", | ||
"authorize_url": "https://AUTH0_DOMAIN/authorize", | ||
"server_metadata_url": "https://AUTH0_DOMAIN/.well-known/" | ||
"openid-configuration", | ||
}, | ||
}, | ||
] | ||
|
||
# start Database | ||
|
@@ -652,3 +668,30 @@ def test_oauth_user_info_azure_with_jwt_validation(self): | |
"username": "b1a54a40-8dfa-4a6d-a2b8-f90b84d4b1df", | ||
}, | ||
) | ||
|
||
def test_oauth_user_info_auth0(self): | ||
self.appbuilder = AppBuilder(self.app, self.db.session) | ||
|
||
self.appbuilder.sm.oauth_remotes["auth0"].userinfo = MagicMock( | ||
return_value={ | ||
"email": "[email protected]", | ||
"given_name": "test", | ||
"family_name": "user", | ||
"role_keys": [], | ||
"sub": "test-sub", | ||
} | ||
) | ||
|
||
user_info = self.appbuilder.sm.get_oauth_user_info( | ||
"auth0", {"access_token": "", "id_token": ""} | ||
) | ||
self.assertEqual( | ||
user_info, | ||
{ | ||
"email": "[email protected]", | ||
"first_name": "test", | ||
"last_name": "user", | ||
"role_keys": [], | ||
"username": "auth0_test-sub", | ||
}, | ||
) |