2021-02-08 10:30:30 +00:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
net_http "net/http"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
http_util "github.com/zitadel/zitadel/internal/api/http"
|
2021-02-08 10:30:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type BrowserInfo struct {
|
|
|
|
UserAgent string
|
|
|
|
AcceptLanguage string
|
|
|
|
RemoteIP net.IP
|
2024-05-16 05:07:56 +00:00
|
|
|
Header net_http.Header
|
2021-02-08 10:30:30 +00: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 05:07:56 +00:00
|
|
|
Header: r.Header,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-03 07:43:34 +00:00
|
|
|
func (a *AuthRequest) ToUserAgent() *UserAgent {
|
|
|
|
agent := &UserAgent{
|
|
|
|
FingerprintID: &a.AgentID,
|
2024-05-16 05:07:56 +00:00
|
|
|
}
|
2024-07-03 07:43:34 +00:00
|
|
|
if a.BrowserInfo == nil {
|
|
|
|
return agent
|
2021-02-08 10:30:30 +00:00
|
|
|
}
|
2024-07-03 07:43:34 +00:00
|
|
|
agent.IP = a.BrowserInfo.RemoteIP
|
|
|
|
agent.Description = &a.BrowserInfo.UserAgent
|
|
|
|
agent.Header = a.BrowserInfo.Header
|
|
|
|
return agent
|
2021-02-08 10:30:30 +00:00
|
|
|
}
|