mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-04 11:52:53 +02:00
device: add generic methods for working with user+session devices (#3710)
This commit is contained in:
parent
6a9d6e45e1
commit
3f9dfbef76
5 changed files with 75 additions and 36 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/pomerium/pomerium/internal/identity"
|
||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
"github.com/pomerium/pomerium/pkg/slices"
|
||||
)
|
||||
|
||||
// Get gets a user from the databroker.
|
||||
|
@ -47,3 +48,18 @@ func (x *User) GetClaim(claim string) []interface{} {
|
|||
}
|
||||
return vs
|
||||
}
|
||||
|
||||
// AddDeviceCredentialID adds a device credential id to the list of device credential ids.
|
||||
func (x *User) AddDeviceCredentialID(deviceCredentialID string) {
|
||||
x.DeviceCredentialIds = slices.Unique(append(x.DeviceCredentialIds, deviceCredentialID))
|
||||
}
|
||||
|
||||
// HasDeviceCredentialID returns true if the user has the device credential id.
|
||||
func (x *User) HasDeviceCredentialID(deviceCredentialID string) bool {
|
||||
return slices.Contains(x.DeviceCredentialIds, deviceCredentialID)
|
||||
}
|
||||
|
||||
// RemoveDeviceCredentialID removes the device credential id from the list of device credential ids.
|
||||
func (x *User) RemoveDeviceCredentialID(deviceCredentialID string) {
|
||||
x.DeviceCredentialIds = slices.Remove(x.DeviceCredentialIds, deviceCredentialID)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue