x

package module
v0.0.0-...-421db18 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: Apache-2.0 Imports: 0 Imported by: 0

README

x

GitHub issues Go Report Card GitHub last commit GitHub go.mod Go version PkgGoDev GitHub

examples

package main

import (
    "github.com/petabytecl/x/errorsx"
    "github.com/petabytecl/x/fmtx"
)

func main() {
    fmtx.JSONPrettyPrint(errorsx.ErrInternalServerError)
}
import (
	"fmt"
	"log"
	"net/http"
	"strconv"

	"github.com/julienschmidt/httprouter"
	"github.com/petabytecl/x/oidcx"
	"golang.org/x/oauth2"
)

const (
	oauthClientID     = "google-client-id"
	oauthClientSecret = "google-client-secret"
)

func main() {
	p, err := oidcx.NewProvider(oauthClientID, oidcx.IssuerGoogle)
	if err != nil {
		fmt.Printf("%s\n", err.Error())
	}

	handler := p.NewOAuth2Handler(
		p.NewOAuth2Config(
			oauthClientSecret,
			"http://localhost:5000/auth/google/callback",
			[]string{
				"openid",
				"https://www.googleapis.com/auth/userinfo.profile",
				"https://www.googleapis.com/auth/userinfo.email",
			},
		),
	)

	fmt.Printf("%s\n",
		handler.AuthCodeURL(
			oauth2.SetAuthURLParam("response_mode", "query"),
			oauth2.SetAuthURLParam("display", "page"),
			oauth2.SetAuthURLParam("prompt", "login consent"),
			oauth2.SetAuthURLParam("max_age", strconv.Itoa(0)),
			oauth2.SetAuthURLParam("ui_locales", "es-CL"),
			oauth2.SetAuthURLParam("id_token_hint", ""),
			oauth2.SetAuthURLParam("login_hint", "foo@bar.com"),
			oauth2.SetAuthURLParam("acr_values", "urn:acr:facial+urn:acr:password"),
		),
	)

	r := httprouter.New()
	r.Handler("GET", "/auth/google/callback", handler)

	log.Fatal(http.ListenAndServe(":5000", r))
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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