Skip to content

Commit

Permalink
Adjust FCM JSON config for getting token
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Aug 26, 2024
1 parent 55586b2 commit a026143
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions handlers/firebase/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,21 +372,19 @@ func (h *handler) getAccessToken(ctx context.Context, channel courier.Channel, c
// fetchAccessToken tries to fetch a new token for our channel, setting the result in redis
func (h *handler) fetchAccessToken(ctx context.Context, channel courier.Channel, clog *courier.ChannelLog) (string, time.Duration, error) {

credentialsFile := channel.StringConfigForKey(configCredentialsFile, "")
if credentialsFile == "" {
credentialsFile := channel.ConfigForKey(configCredentialsFile, nil)
if credentialsFile == nil {

Check warning on line 376 in handlers/firebase/handler.go

View check run for this annotation

Codecov / codecov/patch

handlers/firebase/handler.go#L375-L376

Added lines #L375 - L376 were not covered by tests
return "", 0, courier.ErrChannelConfig
}

var credentialsFileJSON map[string]string

err := json.Unmarshal([]byte(credentialsFile), &credentialsFileJSON)
if err != nil {
credentialsFileJSON, ok := credentialsFile.(map[string]string)
if !ok {

Check warning on line 381 in handlers/firebase/handler.go

View check run for this annotation

Codecov / codecov/patch

handlers/firebase/handler.go#L380-L381

Added lines #L380 - L381 were not covered by tests
return "", 0, courier.ErrChannelConfig
}

sendURL := fmt.Sprintf("https://fcm.googleapis.com/v1/projects/%s/messages:send", credentialsFileJSON["project_id"])

ts, err := idtoken.NewTokenSource(ctx, sendURL, option.WithCredentialsJSON([]byte(credentialsFile)))
ts, err := idtoken.NewTokenSource(ctx, sendURL, option.WithCredentialsJSON(jsonx.MustMarshal(credentialsFileJSON)))

Check warning on line 387 in handlers/firebase/handler.go

View check run for this annotation

Codecov / codecov/patch

handlers/firebase/handler.go#L387

Added line #L387 was not covered by tests
if err != nil {
return "", 0, fmt.Errorf("failed to create NewTokenSource: %w", err)
}
Expand Down

0 comments on commit a026143

Please sign in to comment.