Skip to content

Commit b5f26d9

Browse files
EmyrkBrunoQuaresma
andauthored
feat: add ability for users to convert their password login type to oauth/github login (#8105)
* Currently toggled by experiment flag --------- Co-authored-by: Bruno Quaresma <bruno@coder.com>
1 parent 357f3b3 commit b5f26d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2024
-242
lines changed

cli/server.go

+33
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,39 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
683683
}
684684

685685
options.AppSecurityKey = appSecurityKey
686+
687+
// Read the oauth signing key from the database. Like the app security, generate a new one
688+
// if it is invalid for any reason.
689+
oauthSigningKeyStr, err := tx.GetOAuthSigningKey(ctx)
690+
if err != nil && !xerrors.Is(err, sql.ErrNoRows) {
691+
return xerrors.Errorf("get app oauth signing key: %w", err)
692+
}
693+
if decoded, err := hex.DecodeString(oauthSigningKeyStr); err != nil || len(decoded) != len(options.OAuthSigningKey) {
694+
b := make([]byte, len(options.OAuthSigningKey))
695+
_, err := rand.Read(b)
696+
if err != nil {
697+
return xerrors.Errorf("generate fresh oauth signing key: %w", err)
698+
}
699+
700+
oauthSigningKeyStr = hex.EncodeToString(b)
701+
err = tx.UpsertOAuthSigningKey(ctx, oauthSigningKeyStr)
702+
if err != nil {
703+
return xerrors.Errorf("insert freshly generated oauth signing key to database: %w", err)
704+
}
705+
}
706+
707+
keyBytes, err := hex.DecodeString(oauthSigningKeyStr)
708+
if err != nil {
709+
return xerrors.Errorf("decode oauth signing key from database: %w", err)
710+
}
711+
if len(keyBytes) != len(options.OAuthSigningKey) {
712+
return xerrors.Errorf("oauth signing key in database is not the correct length, expect %d got %d", len(options.OAuthSigningKey), len(keyBytes))
713+
}
714+
copy(options.OAuthSigningKey[:], keyBytes)
715+
if options.OAuthSigningKey == [32]byte{} {
716+
return xerrors.Errorf("oauth signing key in database is empty")
717+
}
718+
686719
return nil
687720
}, nil)
688721
if err != nil {

coderd/apidoc/docs.go

+138-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)