oauth2ns

package module
v0.0.0-...-540b1c7 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2017 License: MIT Imports: 11 Imported by: 1

README

oauth2ns: easy oauth2 for purely client side apps (desktop GUI, cli, mobile)

While oauth works fine for apps the have a server side, I personally find it a pain to use when developing simple desktop or cli applications.
That's why needed something to turn a complete oauth flow into a one-liner (well, that's clearly exaggerated, but it's barely more).

So here's how it works !

Usage

On the web service that you want your app to authenticate into, register you app (aka client) to get a client id and a client secret.

IMPORTANT: you must set the redirection URL to http://127.0.0.1:14565/oauth/callback for this lib to function properly.

Here's an example of creating an app on bitbucket. The UI is usually similar on other web services.

alt text

This will give you the client id and client secret you need to authenticate your apps' users.

And then, from your Go program, authenticate your user like this :

package main

import (
	"github.com/n-marshall/oauth2ns"
	"golang.org/x/oauth2"
)

func main() {
	conf := &oauth2.Config{
		ClientID:     "tRQ9V3cyLxHu3xXFWM",               // also known as slient key sometimes
		ClientSecret: "PZEU9ruk3eZxYvAeCRgS9YyYpAybLG4P", // also known as secret key
		Scopes:       []string{"account"},
		Endpoint: oauth2.Endpoint{
			AuthURL:  "https://bitbucket.org/site/oauth2/authorize",
			TokenURL: "https://bitbucket.org/site/oauth2/access_token",
		},
	}
	/*client := ...*/ _ = oauth2ns.Authorize(conf)
	// use client.Get / client.Post for further requests, the token will automatically be there
}

The AuthURL and TokenURL can be found in the service's oauth documentation.

Documentation

Index

Constants

View Source
const (
	PORT = 14565
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	Client *http.Client
	Token  *oauth2.Token
}

func Authorize

func Authorize(conf *oauth2.Config) *Result

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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