(db *db.DB, cfg *cfg.Cfg, logger *logger.Logger)
| 21 | } |
| 22 | |
| 23 | func 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 | |
| 58 | func (s *OAuthService) CreateOAuthRecord(ctx context.Context, code, state, accessToken string) error { |
| 59 | // Check if state already exists |
no test coverage detected