@@ -33,18 +33,40 @@ def __refresh_identity_cache():
3333 request = requests .get (f"{ KRATOS_ADMIN_URL } /identities" )
3434 if request .ok :
3535 collected = datetime .now ()
36+ identities = request .json ()
37+
38+ # maybe more pages https://www.ory.sh/docs/ecosystem/api-design#pagination
39+ while next_link := __get_link_from_kratos_request (request ):
40+ request = requests .get (next_link )
41+ if request .ok :
42+ identities .extend (request .json ())
43+
3644 KRATOS_IDENTITY_CACHE = {
3745 identity ["id" ]: {
3846 "identity" : identity ,
3947 "simple" : __parse_identity_to_simple (identity ),
4048 }
41- for identity in request . json ()
49+ for identity in identities
4250 }
51+
4352 KRATOS_IDENTITY_CACHE ["collected" ] = collected
4453 else :
4554 KRATOS_IDENTITY_CACHE = {}
4655
4756
57+ def __get_link_from_kratos_request (request : requests .Response ) -> str :
58+ # rel=next only if there is more than 1 page
59+ # </admin/identities?page_size=1&page_token=00000000-0000-0000-0000-000000000000>; rel="first",</admin/identities?page_size=1&page_token=08f30706-9919-4776-9018-6a56c4fa8bb9>; rel="next"
60+ link = request .headers .get ("Link" )
61+ if link :
62+ if 'rel="next"' in link :
63+ parts = link .split ("<" )
64+ for part in parts :
65+ if 'rel="next"' in part :
66+ return part .split (">" )[0 ].replace ("/admin" , KRATOS_ADMIN_URL )
67+ return None
68+
69+
4870def __get_identity (user_id : str , only_simple : bool = True ) -> Dict [str , Any ]:
4971 if not isinstance (user_id , str ):
5072 user_id = str (user_id )
0 commit comments