(ctx context.Context, deviceCodeSignature, userCodeSignature string, r fosite.DeviceRequester, expiresAt time.Time)
| 102 | } |
| 103 | |
| 104 | func (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. |
| 156 | func (p *Persister) CreateDeviceAuthSession(ctx context.Context, deviceCodeSignature, userCodeSignature string, requester fosite.DeviceRequester) (err error) { |
no test coverage detected