auth

package module
v1.1.1-0...-c95dbcb Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: Unlicense Imports: 18 Imported by: 0

README

Planning Center Authentication

Planning Center Authentication can be used to authenticate an Oauth application with the Planning Center API.

The Perform method is the main method for authenticating. It will open a browser, and start an HTTP server to listen for the callback URL on the port specified.

package main

import (
  "fmt"
  "log"

  auth "github.com/maddiesch/pco-auth"
)

func main() {
  input := &auth.PerformInput{
    Port:         8080,
    ClientID:     "0000000000000000000000000000000000000000000000000000000000000000",
    ClientSecret: "0000000000000000000000000000000000000000000000000000000000000000",
    Scopes:       []string{"people"}
  }

  output, err := auth.Perform(&input)
  if err != nil {
    log.Fatal(err)
  }

  fmt.Println(output)
}

Example

See the example CLI app here

Note

Any example & test Client ID & Client Secret values are fake. You will need to create your own at api.planningcenteronline.com/oauth/applications.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// HTTPClient is an overrideable HTTP client for sending requests
	HTTPClient = &http.Client{Timeout: 5 * time.Second}

	// PlanningCenterScheme is the overrideable HTTP scheme for URLs generated
	PlanningCenterScheme = "https"

	// PlanningCenterHost is the overrideable HTTP host for URLs generated
	PlanningCenterHost = "api.planningcenteronline.com"
)

Functions

func AuthorizationURL

func AuthorizationURL(input *AuthorizationURLInput) (*url.URL, error)

AuthorizationURL returns the URL to open in a web browser to start authorization

func Validator

func Validator() *validator.Validate

Validator returns the shared validator instance

Types

type AccessToken

type AccessToken struct {
	Token     string
	Kind      string
	ExpiresIn int64
	Refresh   string
	Scope     string
	CreatedAt int64
}

AccessToken is the Oauth access token used for authorization of requests

func AccessTokenFromCallback

func AccessTokenFromCallback(input *AccessTokenFromCallbackInput) (*AccessToken, error)

AccessTokenFromCallback returns a new access token using the callback URL

func (*AccessToken) PerformRefresh

func (a *AccessToken) PerformRefresh(input *PerformRefreshInput) (*AccessToken, error)

PerformRefresh refreshes the access token and returns a new one.

func (*AccessToken) SignRequest

func (a *AccessToken) SignRequest(req *http.Request)

SignRequest adds the appropriate Authorization header to the request.

type AccessTokenFromCallbackInput

type AccessTokenFromCallbackInput struct {
	CallbackURL  *url.URL `validate:"required"`
	ClientID     string   `validate:"required"`
	ClientSecret string   `validate:"required"`
	RedirectURL  *url.URL `validate:"required"`
	// contains filtered or unexported fields
}

AccessTokenFromCallbackInput is the required parameters for a call to AccessTokenFromCallback

type AuthorizationURLInput

type AuthorizationURLInput struct {
	ClientID    string   `validate:"required,client_token"`
	CallbackURI *url.URL `validate:"required"`
	Scopes      []string `validate:"min=1"`
}

AuthorizationURLInput contains the required parameters for building the authorization URL

type CurrentPerson

type CurrentPerson struct {
	// The authenticated person's organization ID
	OrganizationID string

	// The authenticated person's ID
	PersonID string
}

CurrentPerson represents the authenticated person

func FetchCurrentPerson

func FetchCurrentPerson(input *FetchCurrentPersonInput) (*CurrentPerson, error)

FetchCurrentPerson performs a GET to the Planning Center API to get the current person information.

type Failable

type Failable interface {
	Fail(err error)
}

Failable is a context type that can fail with an error.

type FakeConfig

type FakeConfig struct {
	Logger         *log.Logger
	Scopes         []string
	PersonID       string
	OrganizationID string
}

FakeConfig is the configuration of the fake server

type FakeConfigOutput

type FakeConfigOutput struct {
	ClientID     string
	ClientSecret string
	Code         string
	URL          *url.URL
}

FakeConfigOutput contains the values needed to perform successful requests to the fake server

func SetupForTesting

func SetupForTesting(config *FakeConfig) FakeConfigOutput

SetupForTesting performs the setup for pco-auth to stub all requests to Planning Center and return fake data.

You don't haven't to do anything with the returned URL but it's there if you want to use this as a fake server for something else

type FetchCurrentPersonInput

type FetchCurrentPersonInput struct {
	AccessToken *AccessToken `validate:"required"`
	// contains filtered or unexported fields
}

FetchCurrentPersonInput contains the required parameters for a call to FetchCurrentPerson

type PerformInput

type PerformInput struct {
	// The Oauth client id from api.planningcenteronline.com
	ClientID string `validate:"required,client_token"`

	// The Oauth client secret from api.planningcenteronline.com
	ClientSecret string `validate:"required,client_token"`

	// The scopes to authenticate with
	Scopes []string `validate:"required,min=1"`

	// The HTTP port to start listening on
	Port int `validate:"required"`

	// An optional place where progress data will be written to.
	Logger *log.Logger

	// Should the ID fetch be skipped? If true the output will be empty strings.
	SkipID bool
}

PerformInput is the required values for the input of Perform

type PerformOutput

type PerformOutput struct {
	// The access token that was just authenticated.
	AccessToken *AccessToken

	// The current person's organization id and person id
	CurrentPerson *CurrentPerson `json:",omitempty"`
}

PerformOutput is the output of the Perform function call.

func Perform

func Perform(input *PerformInput) (*PerformOutput, error)

Perform will perform the authorization for Planning Center Oauth

func PerformWithContext

func PerformWithContext(ctx context.Context, input *PerformInput) (*PerformOutput, error)

PerformWithContext performs the authorization for Planning Center Oauth with the passed context

type PerformRefreshInput

type PerformRefreshInput struct {
	// The Oauth client id from api.planningcenteronline.com
	ClientID string `validate:"required,client_token"`

	// The Oauth client secret from api.planningcenteronline.com
	ClientSecret string `validate:"required,client_token"`
	// contains filtered or unexported fields
}

PerformRefreshInput contains the required information from the refresh token

Jump to

Keyboard shortcuts

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