-
-
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.
- Loading branch information
Showing
4 changed files
with
128 additions
and
53 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from flask_appbuilder import AppBuilder, SQLA | ||
from flask_appbuilder.const import AUTH_OAUTH | ||
import jinja2 | ||
import jwt | ||
from tests.const import USERNAME_ADMIN, USERNAME_READONLY | ||
from tests.fixtures.users import create_default_users | ||
|
||
|
@@ -24,9 +25,29 @@ def setUp(self): | |
) | ||
self.app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False | ||
self.app.config["AUTH_TYPE"] = AUTH_OAUTH | ||
self.app.config[ | ||
"OAUTH_PROVIDERS" | ||
] = [] # can be empty, because we dont use the external providers in tests | ||
self.app.config["OAUTH_PROVIDERS"] = [ | ||
{ | ||
"name": "azure", | ||
"icon": "fa-windows", | ||
"token_key": "access_token", | ||
"remote_app": { | ||
"client_id": "CLIENT_ID", | ||
"client_secret": "SECRET", | ||
"api_base_url": "https://login.microsoftonline.com/TENANT_ID/oauth2", | ||
"client_kwargs": { | ||
"scope": "User.Read name email profile", | ||
"resource": "AZURE_APPLICATION_ID", | ||
}, | ||
"request_token_url": None, | ||
"access_token_url": "https://login.microsoftonline.com/" | ||
"AZURE_APPLICATION_ID/" | ||
"oauth2/token", | ||
"authorize_url": "https://login.microsoftonline.com/" | ||
"AZURE_APPLICATION_ID/" | ||
"oauth2/authorize", | ||
}, | ||
} | ||
] | ||
|
||
# start Database | ||
self.db = SQLA(self.app) | ||
|
@@ -437,3 +458,39 @@ def test__registered__jmespath_role__with_role_sync(self): | |
|
||
# validate - user was given the correct roles | ||
self.assertListEqual(user.roles, [sm.find_role("User")]) | ||
|
||
def test_oauth_user_info_azure(self): | ||
|
||
self.appbuilder = AppBuilder(self.app, self.db.session) | ||
claims = { | ||
"aud": "test-aud", | ||
"iss": "https://sts.windows.net/test/", | ||
"iat": 7282182129, | ||
"nbf": 7282182129, | ||
"exp": 1000000000, | ||
"amr": ["pwd"], | ||
"email": "[email protected]", | ||
"family_name": "user", | ||
"given_name": "test", | ||
"idp": "live.com", | ||
"name": "Test user", | ||
"oid": "b1a54a40-8dfa-4a6d-a2b8-f90b84d4b1df", | ||
"unique_name": "live.com#[email protected]", | ||
"ver": "1.0", | ||
} | ||
|
||
# Create an unsigned JWT | ||
unsigned_jwt = jwt.encode(claims, key=None, algorithm="none") | ||
user_info = self.appbuilder.sm.get_oauth_user_info( | ||
"azure", {"access_token": "", "id_token": unsigned_jwt} | ||
) | ||
self.assertEqual( | ||
user_info, | ||
{ | ||
"email": "[email protected]", | ||
"first_name": "test", | ||
"last_name": "user", | ||
"role_keys": [], | ||
"username": "b1a54a40-8dfa-4a6d-a2b8-f90b84d4b1df", | ||
}, | ||
) |
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