2023-04-19 11:46:02 +03:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
2023-04-21 08:58:04 +02:00
|
|
|
"strconv"
|
2023-04-19 11:46:02 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// DeviceAuthState describes the step the
|
|
|
|
// the device authorization process is in.
|
2023-12-20 14:21:08 +02:00
|
|
|
// We generate the Stringer implementation for prettier
|
2023-04-19 11:46:02 +03:00
|
|
|
// log output.
|
|
|
|
//
|
|
|
|
//go:generate stringer -type=DeviceAuthState -linecomment
|
|
|
|
type DeviceAuthState uint
|
|
|
|
|
|
|
|
const (
|
|
|
|
DeviceAuthStateUndefined DeviceAuthState = iota // undefined
|
|
|
|
DeviceAuthStateInitiated // initiated
|
|
|
|
DeviceAuthStateApproved // approved
|
|
|
|
DeviceAuthStateDenied // denied
|
|
|
|
DeviceAuthStateExpired // expired
|
2023-12-20 14:21:08 +02:00
|
|
|
|
|
|
|
deviceAuthStateCount // invalid
|
2023-04-19 11:46:02 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Exists returns true when not Undefined and
|
2023-12-20 14:21:08 +02:00
|
|
|
// any status lower than deviceAuthStateCount.
|
2023-04-19 11:46:02 +03:00
|
|
|
func (s DeviceAuthState) Exists() bool {
|
2023-12-20 14:21:08 +02:00
|
|
|
return s > DeviceAuthStateUndefined && s < deviceAuthStateCount
|
2023-04-19 11:46:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Done returns true when DeviceAuthState is Approved.
|
|
|
|
// This implements the OIDC interface requirement of "Done"
|
|
|
|
func (s DeviceAuthState) Done() bool {
|
|
|
|
return s == DeviceAuthStateApproved
|
|
|
|
}
|
|
|
|
|
|
|
|
// Denied returns true when DeviceAuthState is Denied, Expired or Removed.
|
|
|
|
// This implements the OIDC interface requirement of "Denied".
|
|
|
|
func (s DeviceAuthState) Denied() bool {
|
|
|
|
return s >= DeviceAuthStateDenied
|
|
|
|
}
|
|
|
|
|
2023-04-21 08:58:04 +02:00
|
|
|
func (s DeviceAuthState) GoString() string {
|
|
|
|
return strconv.Itoa(int(s))
|
|
|
|
}
|
|
|
|
|
2023-04-19 11:46:02 +03:00
|
|
|
// DeviceAuthCanceled is a subset of DeviceAuthState, allowed to
|
|
|
|
// be used in the deviceauth.CanceledEvent.
|
|
|
|
// The string type is used to make the eventstore more readable
|
|
|
|
// on the reason of cancelation.
|
|
|
|
type DeviceAuthCanceled string
|
|
|
|
|
|
|
|
const (
|
|
|
|
DeviceAuthCanceledDenied = "denied"
|
|
|
|
DeviceAuthCanceledExpired = "expired"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c DeviceAuthCanceled) State() DeviceAuthState {
|
|
|
|
switch c {
|
|
|
|
case DeviceAuthCanceledDenied:
|
|
|
|
return DeviceAuthStateDenied
|
|
|
|
case DeviceAuthCanceledExpired:
|
|
|
|
return DeviceAuthStateExpired
|
|
|
|
default:
|
|
|
|
return DeviceAuthStateUndefined
|
|
|
|
}
|
|
|
|
}
|