pkce

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package pkce implements the OAuth PKCE Authorization Flow for client applications by starting a server at localhost to receive the web redirect after the user has authorized the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCodeChallenge

func CreateCodeChallenge(n int) (string, string, error)

Types

type BrowserParams

type BrowserParams struct {
	ClientID      string
	Audience      string
	RedirectURI   string
	Scopes        []string
	CodeVerifier  string
	CodeChallenge string
}

BrowserParams are GET query parameters for initiating the PKCE flow.

type CodeResponse

type CodeResponse struct {
	Code  string
	State string
}

CodeResponse represents the code received by the local server's callback handler.

type Flow

type Flow struct {
	// contains filtered or unexported fields
}

Flow holds the state for the steps of OAuth Web Application flow.

func InitFlow

func InitFlow(addr string) (*Flow, error)

InitFlow creates a new Flow instance by detecting a locally available port number.

func (*Flow) AccessToken

func (flow *Flow) AccessToken(tokenURL, redirectURL, codeVerifier string) (*api.Token, error)

AccessToken blocks until the browser flow has completed and returns the access token.

func (*Flow) BrowserURL

func (flow *Flow) BrowserURL(baseURL string, params BrowserParams) (string, error)

BrowserURL appends GET query parameters to baseURL and returns the url that the user should navigate to in their web browser. nolint:gocritic // external code too much risk changing

func (*Flow) StartServer

func (flow *Flow) StartServer(writeSuccess func(io.Writer)) error

StartServer starts the localhost server and blocks until it has received the web redirect. The writeSuccess function can be used to render a HTML page to the user upon completion.

Jump to

Keyboard shortcuts

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