canonical / identity-platform-login-ui

Login UI for the Canonical identity broker and identity provider solution
Apache License 2.0
11 stars 8 forks source link

Remove MethodOnly struct #374

Open nsklikas opened 1 hour ago

nsklikas commented 1 hour ago
          On https://github.com/canonical/identity-platform-login-ui/blob/main/pkg/kratos/service.go#L585 we have a comment about refactoring once we update the sdk version. Is that still valid? Should we open an issue about it or the problem was not solved?

Originally posted by @nsklikas in https://github.com/canonical/identity-platform-login-ui/pull/372#pullrequestreview-2461495884

syncronize-issues-to-jira[bot] commented 1 hour ago

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/IAM-1226.

This message was autogenerated

natalian98 commented 1 hour ago

It looks that we can replace it with SessionAuthenticationMethod:

$ git diff
diff --git a/pkg/kratos/service.go b/pkg/kratos/service.go
index cf97eb1..c1a6272 100644
--- a/pkg/kratos/service.go
+++ b/pkg/kratos/service.go
@@ -75,10 +75,6 @@ type UiErrorMessages struct {
        Ui kClient.UiContainer `json:"ui"`
 }

-type methodOnly struct {
-       Method string `json:"method"`
-}
-
 type LookupSecrets []struct {
        Code   string    `json:"code"`
        UsedAt time.Time `json:"used_at,omitempty"`
@@ -591,7 +587,7 @@ func (s *Service) ParseLoginFlowMethodBody(r *http.Request) (*kClient.UpdateLogi
                ret     kClient.UpdateLoginFlowBody
                cookies = r.Cookies()
        )
-       methodOnly := new(methodOnly)
+       methodOnly := new(kClient.SessionAuthenticationMethod)

        defer r.Body.Close()
        b, err := io.ReadAll(r.Body)
@@ -607,7 +603,7 @@ func (s *Service) ParseLoginFlowMethodBody(r *http.Request) (*kClient.UpdateLogi
                return nil, cookies, err
        }

-       switch methodOnly.Method {
+       switch methodOnly.GetMethod() {
        case "password":
                body := new(kClient.UpdateLoginFlowWithPasswordMethod)

@@ -669,7 +665,7 @@ func (s *Service) ParseLoginFlowMethodBody(r *http.Request) (*kClient.UpdateLogi
                )
        }

-       if s.is1FAMethod(methodOnly.Method) {
+       if s.is1FAMethod(methodOnly.GetMethod()) {
                for i, c := range cookies {
                        if c.Name == KRATOS_SESSION_COOKIE_NAME {
                                if i == len(cookies)-1 {
@@ -703,7 +699,7 @@ func (s *Service) ParseRecoveryFlowMethodBody(r *http.Request) (*kClient.UpdateR
 }

 func (s *Service) ParseSettingsFlowMethodBody(r *http.Request) (*kClient.UpdateSettingsFlowBody, error) {
-       methodOnly := new(methodOnly)
+       methodOnly := new(kClient.SessionAuthenticationMethod)

        defer r.Body.Close()
        b, err := io.ReadAll(r.Body)
@@ -721,7 +717,7 @@ func (s *Service) ParseSettingsFlowMethodBody(r *http.Request) (*kClient.UpdateS

        var ret kClient.UpdateSettingsFlowBody

-       switch methodOnly.Method {
+       switch methodOnly.GetMethod() {
        case "password":
                body := new(kClient.UpdateSettingsFlowWithPasswordMethod)