@@ -7,6 +7,7 @@ defmodule Console.Deployments.Settings do
77 alias Console.Services.Users
88 alias Console.Deployments . { Clusters , Services }
99 alias Console.Schema . { DeploymentSettings , User , Project , BootstrapToken , CloudConnection , FederatedCredential }
10+ require Logger
1011
1112 @ agent_vsn File . read! ( "AGENT_VERSION" ) |> String . trim ( )
1213 @ kube_vsn File . read! ( "KUBE_VERSION" ) |> String . trim ( )
@@ -327,12 +328,12 @@ defmodule Console.Deployments.Settings do
327328 """
328329 @ spec exchange_token ( binary , binary ) :: { :ok , binary } | Console . error ( )
329330 def exchange_token ( token , email ) do
330- user = Users . get_user_by_email !( email )
331+ user = Users . cached_user_by_email !( email )
331332
332- with { :token , { :ok , % { "iss" => issuer } } } <- { :token , Joken . peek_claims ( token ) } ,
333+ with { :token , { :ok , % { "iss" => issuer , "aud" => aud } } } <- { :token , Joken . peek_claims ( token ) } ,
333334 { :config , { :ok , { conf , jwks } } } <- { :config , issuer_configuration ( issuer ) } ,
334335 opts = % { client_jwks: JOSE.JWK . generate_key ( 16 ) } ,
335- ctx = Oidcc.ClientContext . from_manual ( conf , jwks , "dummy_id" , "dummy_secret" , opts ) ,
336+ ctx = Oidcc.ClientContext . from_manual ( conf , jwks , aud , "dummy_secret" , opts ) ,
336337 opts = % { signing_algs: ctx . provider_configuration . id_token_signing_alg_values_supported } ,
337338 { :validate , { :ok , claims } } <- { :validate , Oidcc.Token . validate_jwt ( token , ctx , opts ) } do
338339 FederatedCredential . for_issuer ( issuer )
@@ -344,12 +345,16 @@ defmodule Console.Deployments.Settings do
344345 scopes = Enum . flat_map ( credentials , & & 1 . scopes || [ ] )
345346 |> Enum . uniq ( )
346347 sign_token ( user , scopes )
347- _ -> { :error , "no federated credential for #{ email } match jwt claims" }
348+ _ -> { :error , "no federated credentials for #{ email } match jwt claims" }
348349 end
349350 else
350- { :token , _ } -> { :error , "invalid jwt format" }
351- { :config , _ } -> { :error , "invalid issuer url from jwt" }
352- { :validate , _ } -> { :error , "could not validate jwt" }
351+ { :token , _ } -> { :error , "invalid jwt format, must include iss and aud claims" }
352+ { :config , _ } = res ->
353+ Logger . error ( "failed to fetch issuer configuration: #{ inspect ( res ) } " )
354+ { :error , "invalid issuer url from jwt" }
355+ { :validate , _ } = res ->
356+ Logger . error ( "failed to validate jwt: #{ inspect ( res ) } " )
357+ { :error , "could not validate jwt" }
353358 end
354359 end
355360
@@ -360,12 +365,22 @@ defmodule Console.Deployments.Settings do
360365 end
361366 end
362367
368+ @ quirks % {
369+ quirks: % {
370+ allow_issuer_mismatch: true ,
371+ document_overrides: % {
372+ # needed for atypical oidc implementations like Github's
373+ "authorization_endpoint" => "https://example.com/ignore/oauth/authorize" ,
374+ }
375+ }
376+ }
377+
363378 @ doc """
364379 Fetches the issuer configuration from the issuer url
365380 """
366381 @ decorate cacheable ( cache: @ cache_adapter , key: { :issuer_configuration , issuer } , opts: [ ttl: :timer . minutes ( 60 ) ] )
367382 def issuer_configuration ( issuer ) do
368- with { :ok , { conf , _ } } <- Oidcc.ProviderConfiguration . load_configuration ( issuer , % { quirks: % { allow_issuer_mismatch: true } } ) ,
383+ with { :ok , { conf , _ } } <- Oidcc.ProviderConfiguration . load_configuration ( issuer , @ quirks ) ,
369384 { :ok , { jwks , _ } } <- Oidcc.ProviderConfiguration . load_jwks ( conf . jwks_uri ) ,
370385 do: { :ok , { conf , jwks } }
371386 end
0 commit comments