oauthdialog

package module
v0.0.0-...-5362632 Latest Latest
Warning

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

Go to latest
Published: May 28, 2016 License: MIT Imports: 7 Imported by: 0

README

go-oauthdialog

GoDoc

A Go library to present an OAuth2 dialog to the user.

Usage

package main

import (
	"log"

	"github.com/emersion/go-oauthdialog"
	"golang.org/x/oauth2"
	"golang.org/x/oauth2/google"
)

func main() {
	conf := &oauth2.Config{
		ClientID: "CLIENT_ID",
		ClientSecret: "CLIENT_SECRET",
		Scopes: []string{"https://mail.google.com"},
		Endpoint: google.Endpoint,
	}

	code, err := oauthdialog.Open(conf)
	if err != nil {
		log.Fatal(err)
	}

	tok, err := conf.Exchange(oauth2.NoContext, code)
	if err != nil {
		log.Fatal(err)
	}

	log.Println("Token:", tok)
}

License

MIT

Documentation

Overview

Present OAuth2 dialogs to the user.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRequest          = errors.New("Invalid request")
	ErrUnauthorizedClient      = errors.New("Client not authorized")
	ErrAccessDenied            = errors.New("Access denied")
	ErrUnsupportedResponseType = errors.New("Unsupported response type")
	ErrInvalidScope            = errors.New("Invalid scope")
	ErrServerError             = errors.New("Server error")
	ErrTemporarilyUnavailable  = errors.New("Temporarily unavailable")
)

OAuth2 errors defined in RFC 6749 section 4.1.2.1.

Functions

func Open

func Open(conf *oauth2.Config) (code string, err error)

Create a new OAuth2 dialog and open it.

Types

type Dialog

type Dialog struct {
	// If a value is sent to this channel, the dialog is cancelled.
	Cancel chan bool
	// HTTP handler called when user after user authorization.
	SuccessHandler http.HandlerFunc
	// contains filtered or unexported fields
}

An OAuth2 dialog.

func New

func New(conf *oauth2.Config) *Dialog

Create a new OAuth2 dialog.

func (*Dialog) Open

func (d *Dialog) Open() (code string, err error)

Open the dialog.

Jump to

Keyboard shortcuts

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