MCPcopy
hub / github.com/ory/hydra / sqlDeviceSchemaFromRequest

Method sqlDeviceSchemaFromRequest

persistence/sql/persister_device.go:104–153  ·  view source on GitHub ↗
(ctx context.Context, deviceCodeSignature, userCodeSignature string, r fosite.DeviceRequester, expiresAt time.Time)

Source from the content-addressed store, hash-verified

102}
103
104func (p *Persister) sqlDeviceSchemaFromRequest(ctx context.Context, deviceCodeSignature, userCodeSignature string, r fosite.DeviceRequester, expiresAt time.Time) (*DeviceRequestSQL, error) {
105 subject := ""
106 if r.GetSession() == nil {
107 p.l.Debugf("Got an empty session in sqlSchemaFromRequest")
108 } else {
109 subject = r.GetSession().GetSubject()
110 }
111
112 session, err := json.Marshal(r.GetSession())
113 if err != nil {
114 return nil, errors.WithStack(err)
115 }
116
117 if p.r.Config().EncryptSessionData(ctx) {
118 ciphertext, err := p.r.KeyCipher().Encrypt(ctx, session, nil)
119 if err != nil {
120 return nil, errors.WithStack(err)
121 }
122 session = []byte(ciphertext)
123 }
124
125 var challenge sql.NullString
126 rr, ok := r.GetSession().(*oauth2.Session)
127 if !ok && r.GetSession() != nil {
128 return nil, errors.Errorf("Expected request to be of type *Session, but got: %T", r.GetSession())
129 } else if ok {
130 if len(rr.ConsentChallenge) > 0 {
131 challenge = sql.NullString{Valid: true, String: rr.ConsentChallenge}
132 }
133 }
134
135 return &DeviceRequestSQL{
136 Request: r.GetID(),
137 ConsentChallenge: challenge,
138 ID: deviceCodeSignature,
139 UserCodeID: userCodeSignature,
140 RequestedAt: r.GetRequestedAt(),
141 InternalExpiresAt: sqlxx.NullTime(expiresAt),
142 Client: r.GetClient().GetID(),
143 Scopes: strings.Join(r.GetRequestedScopes(), "|"),
144 GrantedScope: strings.Join(r.GetGrantedScopes(), "|"),
145 GrantedAudience: strings.Join(r.GetGrantedAudience(), "|"),
146 RequestedAudience: strings.Join(r.GetRequestedAudience(), "|"),
147 Form: r.GetRequestForm().Encode(),
148 Session: session,
149 Subject: subject,
150 DeviceCodeActive: true,
151 UserCodeState: r.GetUserCodeState(),
152 }, nil
153}
154
155// CreateDeviceCodeSession creates a new device code session and stores it in the database. Implements DeviceAuthStorage.
156func (p *Persister) CreateDeviceAuthSession(ctx context.Context, deviceCodeSignature, userCodeSignature string, requester fosite.DeviceRequester) (err error) {

Implementers 1

BasePersisterpersistence/sql/persister.go

Calls 15

DebugfMethod · 0.80
EncryptSessionDataMethod · 0.80
GetSessionMethod · 0.65
GetSubjectMethod · 0.65
ConfigMethod · 0.65
EncryptMethod · 0.65
KeyCipherMethod · 0.65
GetIDMethod · 0.65
GetRequestedAtMethod · 0.65
GetClientMethod · 0.65
GetRequestedScopesMethod · 0.65
GetGrantedScopesMethod · 0.65

Tested by

no test coverage detected