iid

package module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2024 License: MIT Imports: 9 Imported by: 0

README

Google Instance ID (FCM Batch APNs Token Import)

Provides a client to bulk import existing iOS APNs tokens to Firebase Cloud Messaging using Google's Instance ID batch import endpoint.

Note, this is a deprecated Google API, so there is no guarantee this will work in the future.

If I get a report it's no longer working, I'll archive the project. ✌️

Installation

go get github.com/matthewhartstonge/iid

Usage

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/matthewhartstonge/iid"
)

func main() {
	jsonCreds, err := os.ReadFile("path-to-firebase-service-account-json.credentials")
	if err != nil {
		panic(err)
	}

	client, err := iid.New("com.example.app", jsonCreds, iid.WithSandbox())
	if err != nil {
		panic(err)
	}

	res, err := client.BatchImport(context.Background(), []string{"MY_APNS_TOKEN"})
	if err != nil {
		panic(err)
	}

	for _, item := range res {
		fmt.Println(item)
	}
}

Firebase Credentials

You will require using Firebase service account credentials which can be downloaded from the Google Cloud Console as a JSON encoded file.

You will need to:

  • Choose your Firebase Project from the Project dropdown selector (top left).
  • Select and click on IAM & Admin > Service accounts from the side menu.
  • Click on your Firebase Admin SDK Service Agent account within the presented table.
  • Click on the 'keys' tab.
  • Click 'Add Key' > 'Create New Key'.
  • Choose key type JSON, and click 'create'.
  • Download and use the JSON file as your service account credentials.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooManyTokens = errors.New("batch import only supports importing " + strconv.Itoa(maxTokens) + " at a time")
)

Functions

This section is empty.

Types

type BatchImportResponse

type BatchImportResponse struct {
	Results []*BatchImportResults `json:"results"`
}

type BatchImportResults

type BatchImportResults struct {
	ApnsToken         string `json:"apns_token"`
	Status            string `json:"status"`
	RegistrationToken string `json:"registration_token"`
}

type Client

type Client struct {
	Application string
	Sandbox     bool
	Scopes      []string
	// contains filtered or unexported fields
}

Client provides the structure required to communicate with Google's IID endpoint.

func New

func New(bundleID string, credentials []byte, opts ...Option) (*Client, error)

New returns a client for importing APNs tokens to Firebase Cloud Messaging (FCM)

func (*Client) BatchImport

func (c *Client) BatchImport(ctx context.Context, tokens []string) ([]*BatchImportResults, error)

BatchImport imports APNs tokens returning an

type Option

type Option func(*Client)

func WithSandbox

func WithSandbox() Option

WithSandbox enables converting sandbox tokens. By default, the client talks to production.

func WithScopes

func WithScopes(scopes []string) Option

WithScopes pushes in your own scopes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL