2021-02-08 11:30:30 +01:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
net_http "net/http"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
http_util "github.com/zitadel/zitadel/internal/api/http"
|
2021-02-08 11:30:30 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type BrowserInfo struct {
|
|
|
|
UserAgent string
|
|
|
|
AcceptLanguage string
|
|
|
|
RemoteIP net.IP
|
2024-05-16 08:07:56 +03:00
|
|
|
Header net_http.Header
|
2021-02-08 11:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func BrowserInfoFromRequest(r *net_http.Request) *BrowserInfo {
|
|
|
|
return &BrowserInfo{
|
|
|
|
UserAgent: r.Header.Get(http_util.UserAgentHeader),
|
|
|
|
AcceptLanguage: r.Header.Get(http_util.AcceptLanguage),
|
|
|
|
RemoteIP: http_util.RemoteIPFromRequest(r),
|
2024-05-16 08:07:56 +03:00
|
|
|
Header: r.Header,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-03 09:43:34 +02:00
|
|
|
func (a *AuthRequest) ToUserAgent() *UserAgent {
|
|
|
|
agent := &UserAgent{
|
|
|
|
FingerprintID: &a.AgentID,
|
2024-05-16 08:07:56 +03:00
|
|
|
}
|
2024-07-03 09:43:34 +02:00
|
|
|
if a.BrowserInfo == nil {
|
|
|
|
return agent
|
2021-02-08 11:30:30 +01:00
|
|
|
}
|
2024-07-03 09:43:34 +02:00
|
|
|
agent.IP = a.BrowserInfo.RemoteIP
|
|
|
|
agent.Description = &a.BrowserInfo.UserAgent
|
|
|
|
agent.Header = a.BrowserInfo.Header
|
|
|
|
return agent
|
2021-02-08 11:30:30 +01:00
|
|
|
}
|