MCPcopy Create free account
hub / github.com/PaperDebugger/paperdebugger / NewOAuthService

Function NewOAuthService

internal/services/oauth.go:23–56  ·  view source on GitHub ↗
(db *db.DB, cfg *cfg.Cfg, logger *logger.Logger)

Source from the content-addressed store, hash-verified

21}
22
23func NewOAuthService(db *db.DB, cfg *cfg.Cfg, logger *logger.Logger) *OAuthService {
24 base := NewBaseService(db, cfg, logger)
25 collection := base.db.Collection((models.OAuth{}).CollectionName())
26
27 indexModels := []mongo.IndexModel{
28 {
29 Keys: bson.D{{Key: "code", Value: 1}},
30 Options: options.Index().
31 SetUnique(true).
32 SetPartialFilterExpression(bson.M{"code": bson.M{"$exists": true}}),
33 },
34 {
35 Keys: bson.D{{Key: "access_token", Value: 1}},
36 Options: options.Index().
37 SetUnique(true).
38 SetPartialFilterExpression(bson.M{"access_token": bson.M{"$exists": true}}),
39 },
40 {
41 Keys: bson.D{{Key: "state", Value: 1}},
42 Options: options.Index().
43 SetUnique(true).
44 SetPartialFilterExpression(bson.M{"state": bson.M{"$exists": true}}),
45 },
46 }
47 _, err := collection.Indexes().CreateMany(context.Background(), indexModels)
48 if err != nil {
49 logger.Error("Failed to create indexes for OAuth collection", err)
50 }
51
52 return &OAuthService{
53 BaseService: base,
54 oauthCollection: collection,
55 }
56}
57
58func (s *OAuthService) CreateOAuthRecord(ctx context.Context, code, state, accessToken string) error {
59 // Check if state already exists

Callers 1

InitializeAppFunction · 0.92

Calls 2

NewBaseServiceFunction · 0.85
CollectionNameMethod · 0.65

Tested by

no test coverage detected