@@ -116,6 +116,51 @@ impl std::fmt::Display for PkceMode {
116116 }
117117}
118118
119+ /// Whether to fetch the user profile from the userinfo endpoint,
120+ /// or to rely on the data returned in the id_token from the token_endpoint
121+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Serialize , Deserialize , Default ) ]
122+ #[ serde( rename_all = "lowercase" ) ]
123+ pub enum UserProfileMethod {
124+ /// Use the userinfo endpoint if `openid` is not included in `scopes`
125+ #[ default]
126+ Auto ,
127+
128+ /// Always use the userinfo endpoint
129+ UserinfoEndpoint ,
130+ }
131+
132+ #[ derive( Debug , Clone , Error ) ]
133+ #[ error( "Invalid user profile method {0:?}" ) ]
134+ pub struct InvalidUserProfileMethodError ( String ) ;
135+
136+ impl std:: str:: FromStr for UserProfileMethod {
137+ type Err = InvalidUserProfileMethodError ;
138+
139+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
140+ match s {
141+ "auto" => Ok ( Self :: Auto ) ,
142+ "userinfo_endpoint" => Ok ( Self :: UserinfoEndpoint ) ,
143+ s => Err ( InvalidUserProfileMethodError ( s. to_owned ( ) ) ) ,
144+ }
145+ }
146+ }
147+
148+ impl UserProfileMethod {
149+ #[ must_use]
150+ pub fn as_str ( self ) -> & ' static str {
151+ match self {
152+ Self :: Auto => "auto" ,
153+ Self :: UserinfoEndpoint => "userinfo_endpoint" ,
154+ }
155+ }
156+ }
157+
158+ impl std:: fmt:: Display for UserProfileMethod {
159+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
160+ f. write_str ( self . as_str ( ) )
161+ }
162+ }
163+
119164#[ derive( Debug , Clone , PartialEq , Eq , Serialize ) ]
120165pub struct UpstreamOAuthProvider {
121166 pub id : Ulid ,
@@ -127,11 +172,13 @@ pub struct UpstreamOAuthProvider {
127172 pub jwks_uri_override : Option < Url > ,
128173 pub authorization_endpoint_override : Option < Url > ,
129174 pub token_endpoint_override : Option < Url > ,
175+ pub userinfo_endpoint_override : Option < Url > ,
130176 pub scope : Scope ,
131177 pub client_id : String ,
132178 pub encrypted_client_secret : Option < String > ,
133179 pub token_endpoint_signing_alg : Option < JsonWebSignatureAlg > ,
134180 pub token_endpoint_auth_method : OAuthClientAuthenticationMethod ,
181+ pub user_profile_method : UserProfileMethod ,
135182 pub created_at : DateTime < Utc > ,
136183 pub disabled_at : Option < DateTime < Utc > > ,
137184 pub claims_imports : ClaimsImports ,
0 commit comments