signin

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package signin signs them in with Apple or Google, using the phone's own sheet. On the phone:

nimbus native plugin add sign-in

u, err := signin.Google(ctx, signin.Options{
	IOSClient:     "123-ios.apps.googleusercontent.com",
	AndroidClient: "123-web.apps.googleusercontent.com",
})

Then send u.IDToken to your server, which checks it with Verify. The other fields are for showing their name: anyone can forge what a phone sends.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("signin: invalid token")

ErrInvalid means the token isn't one to believe.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Nonce is a one-time value from your server. It comes back inside the
	// ID token, so a stolen token can't be replayed.
	Nonce string `json:"nonce,omitempty"`
	// IOSClient is Google's iOS OAuth client ID. Google only.
	IOSClient string `json:"iosClient,omitempty"`
	// AndroidClient is Google's Web OAuth client ID: that kind, not the
	// Android one, which only has to exist. Google only.
	AndroidClient string `json:"androidClient,omitempty"`
}

Options says who's asking.

type User

type User struct {
	Provider string `json:"provider"` // "apple" or "google"
	ID       string `json:"id"`       // theirs for life at that provider
	Email    string `json:"email"`    // their address; Apple may give a private relay
	Name     string `json:"name"`     // their name, when known
	IDToken  string `json:"idToken"`  // for your server to check with Verify
	// Code is Apple's one-time authorization code, for a server that wants
	// refresh tokens. Empty for Google.
	Code string `json:"code"`
}

User is who signed in.

func Apple

func Apple(ctx context.Context, o Options) (User, error)

Apple shows Sign in with Apple. It's iOS only: on Android the error has code plugin.Unavailable. Apple gives their name the first time only, and their email may be a private relay address.

func Google

func Google(ctx context.Context, o Options) (User, error)

Google shows Google's sign-in. On iOS it's Google's page in a secure browser sheet; on Android it's the phone's account sheet.

func Verify

func Verify(ctx context.Context, token string, v Verification) (User, error)

Verify is for your server. It checks an ID token's signature with Apple's or Google's published keys, then who it was issued by and for, and that it hasn't expired. Only trust the User it returns.

type Verification

type Verification struct {
	// Audiences are your client IDs: Apple's is the app's bundle ID,
	// Google's are the ones in Options. A token for another app is refused.
	Audiences []string
	// Nonce is the value you gave the phone. Empty skips the check.
	Nonce string
}

Verification says what a token must be.

Jump to

Keyboard shortcuts

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