UpdateTokenBasic updates or creates a token entry using basic auth
(did string, pds string, accessToken string, refreshToken string, accessExpiry float64, refreshExpiry float64, username string, password string, passwordHash string, passwordSalt string, uuid string)
| 222 | |
| 223 | // UpdateTokenBasic updates or creates a token entry using basic auth |
| 224 | func UpdateTokenBasic(did string, pds string, accessToken string, refreshToken string, accessExpiry float64, refreshExpiry float64, username string, password string, passwordHash string, passwordSalt string, uuid string) (*string, error) { |
| 225 | encryptionKey := authcrypt.DeriveKeyFromPassword(password, passwordSalt) |
| 226 | encryptedAccess, err := authcrypt.Encrypt(accessToken, encryptionKey) |
| 227 | if err != nil { |
| 228 | return nil, fmt.Errorf("failed to encrypt access token: %v", err) |
| 229 | } |
| 230 | |
| 231 | encryptedRefresh, err := authcrypt.Encrypt(refreshToken, encryptionKey) |
| 232 | if err != nil { |
| 233 | return nil, fmt.Errorf("failed to encrypt refresh token: %v", err) |
| 234 | } |
| 235 | |
| 236 | token := Token{ |
| 237 | UserDid: did, |
| 238 | UserPDS: pds, |
| 239 | EncryptedAccessToken: encryptedAccess, |
| 240 | EncryptedRefreshToken: encryptedRefresh, |
| 241 | AccessExpiry: accessExpiry, |
| 242 | RefreshExpiry: refreshExpiry, |
| 243 | BasicAuthHash: passwordHash, |
| 244 | BasicAuthSalt: passwordSalt, |
| 245 | BasicAuthUsername: username, |
| 246 | TokenUUID: uuid, |
| 247 | } |
| 248 | |
| 249 | if err := db.Create(&token).Error; err != nil { |
| 250 | return nil, err |
| 251 | } |
| 252 | |
| 253 | return &token.TokenUUID, nil |
| 254 | } |
| 255 | |
| 256 | // GetToken retrieves account data from the database |
| 257 | // @results: accessToken, refreshToken, accessExpiry, refreshExpiry, pds, error |
no outgoing calls
no test coverage detected