2017-10-03 19:03:58 +05:30
|
|
|
package etcd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
jose "gopkg.in/square/go-jose.v2"
|
2018-09-03 12:14:44 +05:30
|
|
|
|
|
|
|
"github.com/dexidp/dex/storage"
|
2017-10-03 19:03:58 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
// AuthCode is a mirrored struct from storage with JSON struct tags
|
|
|
|
type AuthCode struct {
|
|
|
|
ID string `json:"ID"`
|
|
|
|
ClientID string `json:"clientID"`
|
|
|
|
RedirectURI string `json:"redirectURI"`
|
|
|
|
Nonce string `json:"nonce,omitempty"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
|
|
|
2019-04-18 19:47:31 +05:30
|
|
|
ConnectorID string `json:"connectorID,omitempty"`
|
|
|
|
ConnectorData []byte `json:"connectorData,omitempty"`
|
|
|
|
Claims Claims `json:"claims,omitempty"`
|
2017-10-03 19:03:58 +05:30
|
|
|
|
|
|
|
Expiry time.Time `json:"expiry"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func fromStorageAuthCode(a storage.AuthCode) AuthCode {
|
|
|
|
return AuthCode{
|
2019-04-18 19:47:31 +05:30
|
|
|
ID: a.ID,
|
|
|
|
ClientID: a.ClientID,
|
|
|
|
RedirectURI: a.RedirectURI,
|
|
|
|
ConnectorID: a.ConnectorID,
|
|
|
|
ConnectorData: a.ConnectorData,
|
|
|
|
Nonce: a.Nonce,
|
|
|
|
Scopes: a.Scopes,
|
|
|
|
Claims: fromStorageClaims(a.Claims),
|
|
|
|
Expiry: a.Expiry,
|
2017-10-03 19:03:58 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AuthRequest is a mirrored struct from storage with JSON struct tags
|
|
|
|
type AuthRequest struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
ClientID string `json:"client_id"`
|
|
|
|
|
|
|
|
ResponseTypes []string `json:"response_types"`
|
|
|
|
Scopes []string `json:"scopes"`
|
|
|
|
RedirectURI string `json:"redirect_uri"`
|
|
|
|
Nonce string `json:"nonce"`
|
|
|
|
State string `json:"state"`
|
|
|
|
|
|
|
|
ForceApprovalPrompt bool `json:"force_approval_prompt"`
|
|
|
|
|
|
|
|
Expiry time.Time `json:"expiry"`
|
|
|
|
|
|
|
|
LoggedIn bool `json:"logged_in"`
|
|
|
|
|
|
|
|
Claims Claims `json:"claims"`
|
|
|
|
|
|
|
|
ConnectorID string `json:"connector_id"`
|
|
|
|
ConnectorData []byte `json:"connector_data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func fromStorageAuthRequest(a storage.AuthRequest) AuthRequest {
|
|
|
|
return AuthRequest{
|
|
|
|
ID: a.ID,
|
|
|
|
ClientID: a.ClientID,
|
|
|
|
ResponseTypes: a.ResponseTypes,
|
|
|
|
Scopes: a.Scopes,
|
|
|
|
RedirectURI: a.RedirectURI,
|
|
|
|
Nonce: a.Nonce,
|
|
|
|
State: a.State,
|
|
|
|
ForceApprovalPrompt: a.ForceApprovalPrompt,
|
|
|
|
Expiry: a.Expiry,
|
|
|
|
LoggedIn: a.LoggedIn,
|
|
|
|
Claims: fromStorageClaims(a.Claims),
|
|
|
|
ConnectorID: a.ConnectorID,
|
2019-04-18 19:47:31 +05:30
|
|
|
ConnectorData: a.ConnectorData,
|
2017-10-03 19:03:58 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func toStorageAuthRequest(a AuthRequest) storage.AuthRequest {
|
|
|
|
return storage.AuthRequest{
|
|
|
|
ID: a.ID,
|
|
|
|
ClientID: a.ClientID,
|
|
|
|
ResponseTypes: a.ResponseTypes,
|
|
|
|
Scopes: a.Scopes,
|
|
|
|
RedirectURI: a.RedirectURI,
|
|
|
|
Nonce: a.Nonce,
|
|
|
|
State: a.State,
|
|
|
|
ForceApprovalPrompt: a.ForceApprovalPrompt,
|
|
|
|
LoggedIn: a.LoggedIn,
|
|
|
|
ConnectorID: a.ConnectorID,
|
2019-04-18 19:47:31 +05:30
|
|
|
ConnectorData: a.ConnectorData,
|
2017-10-03 19:03:58 +05:30
|
|
|
Expiry: a.Expiry,
|
|
|
|
Claims: toStorageClaims(a.Claims),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RefreshToken is a mirrored struct from storage with JSON struct tags
|
|
|
|
type RefreshToken struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
|
|
|
Token string `json:"token"`
|
|
|
|
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
LastUsed time.Time `json:"last_used"`
|
|
|
|
|
|
|
|
ClientID string `json:"client_id"`
|
|
|
|
|
|
|
|
ConnectorID string `json:"connector_id"`
|
|
|
|
ConnectorData []byte `json:"connector_data"`
|
|
|
|
Claims Claims `json:"claims"`
|
|
|
|
|
|
|
|
Scopes []string `json:"scopes"`
|
|
|
|
|
|
|
|
Nonce string `json:"nonce"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func toStorageRefreshToken(r RefreshToken) storage.RefreshToken {
|
|
|
|
return storage.RefreshToken{
|
2019-04-18 19:47:31 +05:30
|
|
|
ID: r.ID,
|
|
|
|
Token: r.Token,
|
|
|
|
CreatedAt: r.CreatedAt,
|
|
|
|
LastUsed: r.LastUsed,
|
|
|
|
ClientID: r.ClientID,
|
|
|
|
ConnectorID: r.ConnectorID,
|
|
|
|
ConnectorData: r.ConnectorData,
|
|
|
|
Scopes: r.Scopes,
|
|
|
|
Nonce: r.Nonce,
|
|
|
|
Claims: toStorageClaims(r.Claims),
|
2017-10-03 19:03:58 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func fromStorageRefreshToken(r storage.RefreshToken) RefreshToken {
|
|
|
|
return RefreshToken{
|
2019-04-18 19:47:31 +05:30
|
|
|
ID: r.ID,
|
|
|
|
Token: r.Token,
|
|
|
|
CreatedAt: r.CreatedAt,
|
|
|
|
LastUsed: r.LastUsed,
|
|
|
|
ClientID: r.ClientID,
|
|
|
|
ConnectorID: r.ConnectorID,
|
|
|
|
ConnectorData: r.ConnectorData,
|
|
|
|
Scopes: r.Scopes,
|
|
|
|
Nonce: r.Nonce,
|
|
|
|
Claims: fromStorageClaims(r.Claims),
|
2017-10-03 19:03:58 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Claims is a mirrored struct from storage with JSON struct tags.
|
|
|
|
type Claims struct {
|
2019-10-10 20:13:41 +05:30
|
|
|
UserID string `json:"userID"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
PreferredUsername string `json:"preferredUsername"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
EmailVerified bool `json:"emailVerified"`
|
|
|
|
Groups []string `json:"groups,omitempty"`
|
2017-10-03 19:03:58 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func fromStorageClaims(i storage.Claims) Claims {
|
|
|
|
return Claims{
|
2019-10-10 20:13:41 +05:30
|
|
|
UserID: i.UserID,
|
|
|
|
Username: i.Username,
|
|
|
|
PreferredUsername: i.PreferredUsername,
|
|
|
|
Email: i.Email,
|
|
|
|
EmailVerified: i.EmailVerified,
|
|
|
|
Groups: i.Groups,
|
2017-10-03 19:03:58 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func toStorageClaims(i Claims) storage.Claims {
|
|
|
|
return storage.Claims{
|
2019-10-10 20:13:41 +05:30
|
|
|
UserID: i.UserID,
|
|
|
|
Username: i.Username,
|
|
|
|
PreferredUsername: i.PreferredUsername,
|
|
|
|
Email: i.Email,
|
|
|
|
EmailVerified: i.EmailVerified,
|
|
|
|
Groups: i.Groups,
|
2017-10-03 19:03:58 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keys is a mirrored struct from storage with JSON struct tags
|
|
|
|
type Keys struct {
|
|
|
|
SigningKey *jose.JSONWebKey `json:"signing_key,omitempty"`
|
|
|
|
SigningKeyPub *jose.JSONWebKey `json:"signing_key_pub,omitempty"`
|
|
|
|
VerificationKeys []storage.VerificationKey `json:"verification_keys"`
|
|
|
|
NextRotation time.Time `json:"next_rotation"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// OfflineSessions is a mirrored struct from storage with JSON struct tags
|
|
|
|
type OfflineSessions struct {
|
2018-01-30 02:41:59 +05:30
|
|
|
UserID string `json:"user_id,omitempty"`
|
|
|
|
ConnID string `json:"conn_id,omitempty"`
|
|
|
|
Refresh map[string]*storage.RefreshTokenRef `json:"refresh,omitempty"`
|
|
|
|
ConnectorData []byte `json:"connectorData,omitempty"`
|
2017-10-03 19:03:58 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func fromStorageOfflineSessions(o storage.OfflineSessions) OfflineSessions {
|
|
|
|
return OfflineSessions{
|
2018-01-30 02:41:59 +05:30
|
|
|
UserID: o.UserID,
|
|
|
|
ConnID: o.ConnID,
|
|
|
|
Refresh: o.Refresh,
|
|
|
|
ConnectorData: o.ConnectorData,
|
2017-10-03 19:03:58 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func toStorageOfflineSessions(o OfflineSessions) storage.OfflineSessions {
|
|
|
|
s := storage.OfflineSessions{
|
2018-01-30 02:41:59 +05:30
|
|
|
UserID: o.UserID,
|
|
|
|
ConnID: o.ConnID,
|
|
|
|
Refresh: o.Refresh,
|
|
|
|
ConnectorData: o.ConnectorData,
|
2017-10-03 19:03:58 +05:30
|
|
|
}
|
|
|
|
if s.Refresh == nil {
|
|
|
|
// Server code assumes this will be non-nil.
|
|
|
|
s.Refresh = make(map[string]*storage.RefreshTokenRef)
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
2020-01-16 21:25:07 +05:30
|
|
|
|
|
|
|
// DeviceRequest is a mirrored struct from storage with JSON struct tags
|
|
|
|
type DeviceRequest struct {
|
2020-02-04 20:37:18 +05:30
|
|
|
UserCode string `json:"user_code"`
|
|
|
|
DeviceCode string `json:"device_code"`
|
|
|
|
ClientID string `json:"client_id"`
|
|
|
|
ClientSecret string `json:"client_secret"`
|
|
|
|
Scopes []string `json:"scopes"`
|
|
|
|
Expiry time.Time `json:"expiry"`
|
2020-01-16 21:25:07 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func fromStorageDeviceRequest(d storage.DeviceRequest) DeviceRequest {
|
|
|
|
return DeviceRequest{
|
2020-02-04 20:37:18 +05:30
|
|
|
UserCode: d.UserCode,
|
|
|
|
DeviceCode: d.DeviceCode,
|
|
|
|
ClientID: d.ClientID,
|
|
|
|
ClientSecret: d.ClientSecret,
|
|
|
|
Scopes: d.Scopes,
|
|
|
|
Expiry: d.Expiry,
|
2020-01-16 21:25:07 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeviceToken is a mirrored struct from storage with JSON struct tags
|
|
|
|
type DeviceToken struct {
|
2020-01-29 00:44:30 +05:30
|
|
|
DeviceCode string `json:"device_code"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
Token string `json:"token"`
|
|
|
|
Expiry time.Time `json:"expiry"`
|
|
|
|
LastRequestTime time.Time `json:"last_request"`
|
|
|
|
PollIntervalSeconds int `json:"poll_interval"`
|
2020-01-16 21:25:07 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func fromStorageDeviceToken(t storage.DeviceToken) DeviceToken {
|
|
|
|
return DeviceToken{
|
2020-01-29 00:44:30 +05:30
|
|
|
DeviceCode: t.DeviceCode,
|
|
|
|
Status: t.Status,
|
|
|
|
Token: t.Token,
|
|
|
|
Expiry: t.Expiry,
|
|
|
|
LastRequestTime: t.LastRequestTime,
|
|
|
|
PollIntervalSeconds: t.PollIntervalSeconds,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func toStorageDeviceToken(t DeviceToken) storage.DeviceToken {
|
|
|
|
return storage.DeviceToken{
|
|
|
|
DeviceCode: t.DeviceCode,
|
|
|
|
Status: t.Status,
|
|
|
|
Token: t.Token,
|
|
|
|
Expiry: t.Expiry,
|
|
|
|
LastRequestTime: t.LastRequestTime,
|
|
|
|
PollIntervalSeconds: t.PollIntervalSeconds,
|
2020-01-16 21:25:07 +05:30
|
|
|
}
|
|
|
|
}
|