@@ -213,18 +213,18 @@ func NewHydraKratosClientFromConfig(cfg *HydraKratosConfig) (*HydraKratosClient,
213213
214214// NewHydraKratosClient creates a new client with the default config.
215215func NewHydraKratosClient () (* HydraKratosClient , error ) {
216- return NewHydraKratosClientFromConfig (
217- & HydraKratosConfig {
218- HydraPublicHost : viper .GetString ("hydra_public_host " ),
219- HydraAdminHost : viper .GetString ("hydra_admin_host " ),
220- HydraBrowserURL : viper .GetString ("hydra_browser_url " ),
221- KratosPublicHost : viper .GetString ("kratos_public_host " ),
222- KratosAdminHost : viper .GetString ("kratos_admin_host " ),
223- KratosBrowserURL : viper .GetString ("kratos_browser_url " ),
224- HydraConsentPath : viper .GetString ("hydra_consent_path " ),
225- HydraClientID : viper . GetString ( "hydra_client_id" ),
226- },
227- )
216+ config := & HydraKratosConfig {
217+ HydraPublicHost : viper . GetString ( "hydra_public_host" ),
218+ HydraAdminHost : viper .GetString ("hydra_admin_host " ),
219+ HydraBrowserURL : viper .GetString ("hydra_browser_url " ),
220+ KratosPublicHost : viper .GetString ("kratos_public_host " ),
221+ KratosAdminHost : viper .GetString ("kratos_admin_host " ),
222+ KratosBrowserURL : viper .GetString ("kratos_browser_url " ),
223+ HydraConsentPath : viper .GetString ("hydra_consent_path " ),
224+ HydraClientID : viper .GetString ("hydra_client_id " ),
225+ }
226+ fmt . Printf ( "Using hydra kratos config: %+v \n " , config )
227+ return NewHydraKratosClientFromConfig ( config )
228228}
229229
230230func (c * HydraKratosClient ) convertExternalHydraURLToInternal (externalHydraURL string ) (string , error ) {
@@ -450,9 +450,11 @@ func (c *HydraKratosClient) AcceptConsent(ctx context.Context, challenge string)
450450
451451 // We only trust the client that's passed in as a config here. In the future we might want to support other clients
452452 // at which point we will want to actually ask for permission from the user.
453- if consentRequest .Client .ClientID != c .Config .HydraClientID {
454- return nil , fmt .Errorf ("'%s' not an allowed client" , consentRequest .Client .ClientID )
455- }
453+
454+ // TODO(ddelnano): This needs cannot be hard coded to auth-code-client, but should be set in the config.
455+ // if consentRequest.Client.ClientID != c.Config.HydraClientID {
456+ // return nil, fmt.Errorf("'%s' not an allowed client", consentRequest.Client.ClientID)
457+ // }
456458
457459 acceptResp , err := c .hydraAdminClient .AcceptConsentRequest (& hydraAdmin.AcceptConsentRequestParams {
458460 Body : & hydraModels.AcceptConsentRequest {
@@ -505,12 +507,15 @@ func (c *HydraKratosClient) HandleLogin(session *sessions.Session, w http.Respon
505507 ctx := context .Background ()
506508 whoami , err := c .Whoami (ctx , r )
507509 if err != nil {
508- return & handler.StatusError {Code : http .StatusInternalServerError , Err : err }
510+ return & handler.StatusError {Code : http .StatusInternalServerError , Err : fmt . Errorf ( "Could not get whoami: %w" , err ) }
509511 }
510512
513+ if whoami != nil && whoami .kratosSession != nil {
514+ fmt .Printf ("session: %+v\n " , * whoami .kratosSession )
515+ }
511516 redirectResp , err := c .AcceptHydraLogin (ctx , challenge , whoami )
512517 if err != nil {
513- return & handler.StatusError {Code : http .StatusInternalServerError , Err : err }
518+ return & handler.StatusError {Code : http .StatusInternalServerError , Err : fmt . Errorf ( "Could not accept hydra login: %w" , err ) }
514519 }
515520
516521 if redirectResp .RedirectTo == nil {
@@ -520,12 +525,12 @@ func (c *HydraKratosClient) HandleLogin(session *sessions.Session, w http.Respon
520525 // We expect the response to redirect to the consent endpoint. We will just intercept the consent endpoint
521526 respHeader , consentChallenge , err := c .InterceptHydraUserConsent (* redirectResp .RedirectTo , r .Header )
522527 if err != nil {
523- return & handler.StatusError {Code : http .StatusInternalServerError , Err : err }
528+ return & handler.StatusError {Code : http .StatusInternalServerError , Err : fmt . Errorf ( "Could not intercept hydra user consent: %w" , err ) }
524529 }
525530
526531 consentResp , err := c .AcceptConsent (ctx , consentChallenge )
527532 if err != nil {
528- return & handler.StatusError {Code : http .StatusInternalServerError , Err : err }
533+ return & handler.StatusError {Code : http .StatusInternalServerError , Err : fmt . Errorf ( "Could not accept hydra consent: %w" , err ) }
529534 }
530535
531536 // Copy the header because the header contains a necessary Set-Cookie from the OAuth server.
0 commit comments