Skip to content

Commit

Permalink
FIXES: TOTP
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryan51203 committed Dec 23, 2024
1 parent 02b808e commit 87a7bff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
12 changes: 10 additions & 2 deletions api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func HandlePostLoginFlow(c *gin.Context) {

identity, session, err := login.SubmitLoginFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Password, t.Identifier) // _ is USERID

if err != nil {
if session == "" {
log.ErrorLogger("Post login flow failed", err)

errCode, _ := strconv.Atoi((strings.Split(err.Error(), " "))[0])
Expand All @@ -75,8 +75,16 @@ func HandlePostLoginFlow(c *gin.Context) {
})
return
}

c.SetCookie("sdslabs_session", session, 3600, "/", config.NymeriaConfig.URL.Domain, true, true)

if err != nil {
c.JSON(http.StatusOK, gin.H{
"status": "aal1 done",
"person": nil,
})
return
}

c.JSON(http.StatusOK, gin.H{
"status": "user logged in",
"person": identity,
Expand Down
30 changes: 3 additions & 27 deletions api/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ func HandleGetSettingsFlow(c *gin.Context) {

if err != nil {
log.ErrorLogger("Initialize Settings flow Failed", err)
c.JSON(http.StatusInternalServerError, gin.H{
"error": "internal server error",
errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0])
c.JSON(errCode, gin.H{
"error": err.Error(),
})
return
}
Expand Down Expand Up @@ -69,31 +70,6 @@ func HandleGetSettingsFlow(c *gin.Context) {
}
}

session, err := middleware.GetSession(c)
if err != nil {
log.ErrorLogger("Unable to get session", err)
errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0])
c.JSON(errCode, gin.H{
"error": err.Error(),
"message": "Unable to get session",
})
return
}
identity := session.GetIdentity()
traits := identity.GetTraits().(map[string]interface{})

_, err = settings.SubmitSettingsFlowProfileMethod(flow_cookie, session_cookie, flowID, csrf_token, traits)
if err != nil {
log.ErrorLogger("Kratos post settings update profile flow failed", err)

errCode, _ := strconv.Atoi((strings.Split(err.Error(), " "))[0])
c.JSON(errCode, gin.H{
"error": err.Error(),
"message": "Kratos post settings update profile flow failed",
})
return
}

c.JSON(http.StatusOK, gin.H{
"flowID": flowID,
"csrf_token": csrf_token,
Expand Down
10 changes: 7 additions & 3 deletions pkg/wrapper/kratos/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ func SubmitLoginFlowWrapper(cookie string, flowID string, csrfToken string, pass
apiClient := client.NewAPIClient(config.KratosClientConfig)

resp, r, err := apiClient.FrontendAPI.UpdateLoginFlow(context.Background()).Cookie(cookie).Flow(flowID).XSessionToken("").UpdateLoginFlowBody(submitDataBody).Execute()
if err != nil {
return *client.NewSessionWithDefaults(), "", err
}

responseCookies := r.Header["Set-Cookie"]

if err != nil {
if responseCookies == nil {
return *client.NewSessionWithDefaults(), "", err
}
return *client.NewSessionWithDefaults(), responseCookies[1], err
}

return resp.Session, responseCookies[1], nil
}

Expand Down

0 comments on commit 87a7bff

Please sign in to comment.