mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-08-24 21:17:31 +00:00
Co-authored-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
33 lines
696 B
Go
33 lines
696 B
Go
package oidc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ory/fosite/handler/rfc8628"
|
|
"github.com/pocket-id/pocket-id/backend/internal/utils"
|
|
)
|
|
|
|
const (
|
|
oauthDeviceUserCodePrefix = "E"
|
|
oauthDeviceUserCodeRandomLength = 7
|
|
)
|
|
|
|
type deviceStrategy struct {
|
|
*rfc8628.DefaultDeviceStrategy
|
|
}
|
|
|
|
func (s *deviceStrategy) GenerateUserCode(ctx context.Context) (string, string, error) {
|
|
userCode, err := utils.GenerateRandomUppercaseUnambiguousString(oauthDeviceUserCodeRandomLength)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
|
|
userCode = oauthDeviceUserCodePrefix + userCode
|
|
signature, err := s.UserCodeSignature(ctx, userCode)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
|
|
return userCode, signature, nil
|
|
}
|