Skip to content

Commit

Permalink
feat: let DB generate ID for session devices
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Feb 13, 2023
1 parent bf828d3 commit 62402c7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/ory/herodot"
"github.com/ory/kratos/identity"
"github.com/ory/kratos/x"
"github.com/ory/x/randx"
)

Expand Down Expand Up @@ -234,24 +233,22 @@ func (s *Session) Activate(r *http.Request, i *identity.Identity, c lifespanProv
s.Identity = i
s.IdentityID = i.ID

s.SaveSessionDeviceInformation(r)
s.SetSessionDeviceInformation(r)
s.SetAuthenticatorAssuranceLevel()
return nil
}

func (s *Session) SaveSessionDeviceInformation(r *http.Request) {
var device Device

device.ID = x.NewUUID()
device.SessionID = s.ID
func (s *Session) SetSessionDeviceInformation(r *http.Request) {
device := Device{
SessionID: s.ID,
IPAddress: stringsx.GetPointer(httpx.ClientIP(r)),
}

agent := r.Header["User-Agent"]
if len(agent) > 0 {
device.UserAgent = stringsx.GetPointer(strings.Join(agent, " "))
}

device.IPAddress = stringsx.GetPointer(httpx.ClientIP(r))

var clientGeoLocation []string
if r.Header.Get("Cf-Ipcity") != "" {
clientGeoLocation = append(clientGeoLocation, r.Header.Get("Cf-Ipcity"))
Expand Down

0 comments on commit 62402c7

Please sign in to comment.