Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove MethodOnly struct #374

Open
nsklikas opened this issue Nov 26, 2024 · 2 comments
Open

Remove MethodOnly struct #374

nsklikas opened this issue Nov 26, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@nsklikas
Copy link
Contributor

          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 #372 (review)

@nsklikas nsklikas added the enhancement New feature or request label Nov 26, 2024
Copy link

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
Copy link
Contributor

natalian98 commented Nov 26, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants