appleLogin

package module
v0.0.0-...-916f5b8 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: MIT Imports: 10 Imported by: 0

README

appleLogin

A tool for Sign In with Apple REST API written in Golang

go-report

logo here

What it dose?
  • Full support of JWT Authorization for Apple Developer
  • Quick API to finish Sign In with Apple REST API on Apple Document
  • Tool to create callBackURL
Install:

go get github.com/BillSJC/appleLogin

Test:

go test

Quick Start
package main

import (
	"fmt"
	"github.com/BillSJC/appleLogin"
)

func main(){
	a := appleLogin.InitAppleConfig("123ABC456D",   //Team ID
		"com.example.pkg",  //Client ID (Service ID)
		"https://www.example.com/callback", //Callback URL
		"your Apple Key ID")    //Key ID
		
	//import cert
	err := a.LoadP8CertByFile("path to your p8 cert file")  //path to cert file
	//or you can load cert from a string
	err = a.LoadP8CertByByte([]byte("set your cert string here"))
	
	if err != nil {
		panic(err)
	}
	
	//create callback URL
	callbackURL := a.CreateCallbackURL("state here")
	fmt.Println(callbackURL)
	
	// ... some code to get Apple`s AuthorizationCode
	code := "xxxx"
	token,err := a.GetAppleToken(code,3600)
	if err != nil {
		panic(err)
	}
	fmt.Println(token)

}

Functions
InitAppleConfig
LoadP8CertByFile
LoadP8CertByByte
CreateCallbackURL
GetAppleToken

Documentation

Index

Constants

View Source
const AppleAuthURL = "https://appleid.apple.com/auth/token" //the auth URL of apple
View Source
const AppleGrantType = "authorization_code" //the grant type of apple auth

Variables

This section is empty.

Functions

This section is empty.

Types

type AppleAuthToken

type AppleAuthToken struct {
	AccessToken  string `json:"access_token"`  //AccessToken
	ExpiresIn    int64  `json:"expires_in"`    //Expires in
	IDToken      string `json:"id_token"`      //ID token
	RefreshToken string `json:"refresh_token"` //RF token
	TokenType    string `json:"token_type"`    //Token Type
}

AppleAuthToken main response of apple REST-API

type AppleConfig

type AppleConfig struct {
	TeamID      string      //Your Apple Team ID
	ClientID    string      //Your Service which enable sign-in-with-apple service
	RedirectURI string      //Your RedirectURI config in apple website
	KeyID       string      //Your Secret Key ID
	AESCert     interface{} //Your Secret Key Created By X509 package
}

AppleConfig Main struct of the package

func InitAppleConfig

func InitAppleConfig(teamID string, clientID string, redirectURI string, keyID string) *AppleConfig

InitAppleConfig init a new Client of this pkg

func (*AppleConfig) CreateCallbackURL

func (a *AppleConfig) CreateCallbackURL(state string) string

CreateCallbackURL create a callback URL for frontend

func (*AppleConfig) GetAppleToken

func (a *AppleConfig) GetAppleToken(code string, expireTime int64) (*AppleAuthToken, error)

input your code and expire-time to get AccessToken of apple

func (*AppleConfig) LoadP8CertByByte

func (a *AppleConfig) LoadP8CertByByte(str []byte) (err error)

LoadP8CertByByte use x509.ParsePKCS8PrivateKey to Parse cert file

func (*AppleConfig) LoadP8CertByFile

func (a *AppleConfig) LoadP8CertByFile(path string) (err error)

LoadP8CertByFile load file and Parse it

Jump to

Keyboard shortcuts

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