|
14 | 14 | from fastapi import FastAPI
|
15 | 15 | from pytest import mark, fixture
|
16 | 16 | from starlette.testclient import TestClient
|
| 17 | +from typing import Any, Dict |
17 | 18 |
|
18 | 19 | from supertokens_python import init
|
19 | 20 | from supertokens_python.framework.fastapi import get_middleware
|
|
47 | 48 | from supertokens_python.recipe.thirdparty.provider import (
|
48 | 49 | ProviderConfig,
|
49 | 50 | ProviderClientConfig,
|
| 51 | + UserInfoMap, |
| 52 | + UserFields, |
50 | 53 | )
|
51 | 54 |
|
52 | 55 |
|
@@ -130,28 +133,100 @@ async def test_tenant_thirdparty_config():
|
130 | 133 | tenant_config = await get_tenant("t1")
|
131 | 134 |
|
132 | 135 | assert len(tenant_config.third_party.providers) == 1
|
133 |
| - assert tenant_config.third_party.providers[0].third_party_id == "google" |
134 |
| - assert tenant_config.third_party.providers[0].clients is not None |
135 |
| - assert len(tenant_config.third_party.providers[0].clients) == 1 |
136 |
| - assert tenant_config.third_party.providers[0].clients[0].client_id == "abcd" |
| 136 | + provider = tenant_config.third_party.providers[0] |
| 137 | + assert provider.third_party_id == "google" |
| 138 | + assert provider.clients is not None |
| 139 | + assert len(provider.clients) == 1 |
| 140 | + assert provider.clients[0].client_id == "abcd" |
| 141 | + assert provider.clients[0].client_secret is None |
| 142 | + assert provider.clients[0].force_pkce is False |
| 143 | + assert provider.require_email is True |
| 144 | + |
| 145 | + async def validate_id_token_payload( |
| 146 | + _: Dict[str, Any], __: Any, ___: Dict[str, Any] |
| 147 | + ): |
| 148 | + return |
| 149 | + |
| 150 | + async def generate_fake_email(_: str, __: Dict[str, Any]): |
| 151 | + |
137 | 152 |
|
138 | 153 | # update thirdparty config
|
139 | 154 | await create_or_update_third_party_config(
|
140 | 155 | "t1",
|
141 | 156 | ProviderConfig(
|
142 | 157 | third_party_id="google",
|
143 | 158 | name="Custom name",
|
144 |
| - clients=[ProviderClientConfig(client_id="efgh")], |
| 159 | + clients=[ |
| 160 | + ProviderClientConfig( |
| 161 | + client_id="efgh", |
| 162 | + client_secret="ijkl", |
| 163 | + scope=["m", "n"], |
| 164 | + force_pkce=True, |
| 165 | + additional_config={"o": "p"}, |
| 166 | + ) |
| 167 | + ], |
| 168 | + authorization_endpoint="http://localhost:8080/auth", |
| 169 | + authorization_endpoint_query_params={"a": "b"}, |
| 170 | + token_endpoint="http://localhost:8080/token", |
| 171 | + token_endpoint_body_params={"c": "d"}, |
| 172 | + user_info_endpoint="http://localhost:8080/userinfo", |
| 173 | + user_info_endpoint_query_params={"e": "f"}, |
| 174 | + user_info_endpoint_headers={"g": "h"}, |
| 175 | + jwks_uri="http://localhost:8080/.well-known/jwks.json", |
| 176 | + oidc_discovery_endpoint="http://localhost:8080/.well-known/openid-configuration", |
| 177 | + user_info_map=UserInfoMap( |
| 178 | + from_id_token_payload=UserFields( |
| 179 | + user_id="userid", |
| 180 | + email="email", |
| 181 | + email_verified="is_verified", |
| 182 | + ), |
| 183 | + from_user_info_api=UserFields(), |
| 184 | + ), |
| 185 | + require_email=False, |
| 186 | + validate_id_token_payload=validate_id_token_payload, |
| 187 | + generate_fake_email=generate_fake_email, |
145 | 188 | ),
|
146 | 189 | )
|
147 | 190 |
|
148 | 191 | tenant_config = await get_tenant("t1")
|
149 | 192 | assert len(tenant_config.third_party.providers) == 1
|
150 |
| - assert tenant_config.third_party.providers[0].third_party_id == "google" |
151 |
| - assert tenant_config.third_party.providers[0].name == "Custom name" |
152 |
| - assert tenant_config.third_party.providers[0].clients is not None |
153 |
| - assert len(tenant_config.third_party.providers[0].clients) == 1 |
154 |
| - assert tenant_config.third_party.providers[0].clients[0].client_id == "efgh" |
| 193 | + provider = tenant_config.third_party.providers[0] |
| 194 | + assert provider.third_party_id == "google" |
| 195 | + assert provider.name == "Custom name" |
| 196 | + assert provider.clients is not None |
| 197 | + assert len(provider.clients) == 1 |
| 198 | + assert provider.clients[0].client_id == "efgh" |
| 199 | + assert provider.clients[0].client_secret == "ijkl" |
| 200 | + assert provider.clients[0].scope == ["m", "n"] |
| 201 | + assert provider.clients[0].force_pkce is True |
| 202 | + assert provider.clients[0].additional_config == {"o": "p"} |
| 203 | + |
| 204 | + assert provider.name == "Custom name" |
| 205 | + assert provider.authorization_endpoint == "http://localhost:8080/auth" |
| 206 | + assert provider.authorization_endpoint_query_params == {"a": "b"} |
| 207 | + assert provider.token_endpoint == "http://localhost:8080/token" |
| 208 | + assert provider.token_endpoint_body_params == {"c": "d"} |
| 209 | + assert provider.user_info_endpoint == "http://localhost:8080/userinfo" |
| 210 | + assert provider.user_info_endpoint_query_params == {"e": "f"} |
| 211 | + assert provider.user_info_endpoint_headers == {"g": "h"} |
| 212 | + assert provider.jwks_uri == "http://localhost:8080/.well-known/jwks.json" |
| 213 | + assert ( |
| 214 | + provider.oidc_discovery_endpoint |
| 215 | + == "http://localhost:8080/.well-known/openid-configuration" |
| 216 | + ) |
| 217 | + |
| 218 | + assert provider.user_info_map is not None |
| 219 | + assert provider.user_info_map.from_id_token_payload.user_id == "userid" |
| 220 | + assert provider.user_info_map.from_id_token_payload.email == "email" |
| 221 | + assert provider.user_info_map.from_id_token_payload.email_verified == "is_verified" |
| 222 | + assert provider.user_info_map.from_user_info_api is not None |
| 223 | + assert provider.user_info_map.from_user_info_api.user_id is None |
| 224 | + assert provider.user_info_map.from_user_info_api.email is None |
| 225 | + assert provider.user_info_map.from_user_info_api.email_verified is None |
| 226 | + |
| 227 | + assert provider.require_email is False |
| 228 | + assert provider.validate_id_token_payload is None |
| 229 | + assert provider.generate_fake_email is None |
155 | 230 |
|
156 | 231 | # delete thirdparty config
|
157 | 232 | await delete_third_party_config("t1", "google")
|
|
0 commit comments