beegoutil

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2021 License: MIT Imports: 9 Imported by: 0

README

Beego OAuth 2.0 Demo

Build Status Go Report Card Docs License

A Beego example app to demo OAuth 2.0 using Google and Facebook.

The following are used in this example app:

Usage

App Hostname / OAuth 2.0 Redirect URI

Decide on the hostname for your app which will be used in the OAuth 2.0 URI.

The redirect URI is oauth2callback. For example, if your app URL is https://example.com, your redirect URI will be https://example.com/oauth2callback.

If you do not have an Internet accessible hostname, you can use ngrok for testing.

Configure Google and Facebook

Login to the Google and Facebbook developer consoles to configure your apps with your OAuth 2.0 rediect URIs. During this process, you will get your OAuth 2.0 client ID and client secrets for Google and Facebook.

Install & Configure App
  1. Clone the repo
  2. Install the dependencies
  3. Set up your app.conf file.
  4. Run the app

You can do the above with the following steps. See the next section for more detailed information on the configuration file.

$ git clone https://github.com/grokify/beego-oauth2-demo
$ go get ./...
$ cd beego-oauth2-demo/conf
$ cp app.conf.sample app.conf
$ vim app.conf
$ bee run
Configuration File

This is a basic Beego config file with additional properties. Specifically, it has the following 3 properties:

Property Description
oauth2redirecturi This app's OAuth2 redirect URI which has the path /oauth2callback, e.g. https://example.com/oauth2callback
oauth2configgoogle The Google Developers Console client_credentials.json file information. Nagivate to "API Manager" > "Credentials" > "OAuth 2.0 client IDs" > > "Download JSON". This is read directly by OAuth2's google.ConfigFromJSON() function.
oauth2configfacebook This uses the format used by oauth2.Config

References

Google Auth Credentials

App credentials are created an managed using the Google Developers Console. To create an app, do the following:

  1. Navigate to Google Developers Console
  2. Click "API Manager"
  3. Create / Select a Project
  4. Click "Credentials"
  5. Create / Select OAuth 2.0 client IDs for "Web application"
  6. Click "Download JSON"

Documentation

Index

Constants

View Source
const (
	BeegoOauth2ProvidersCfgVar    string = "oauth2providers"
	BeegoOauth2ConfigCfgVarPrefix string = "oauth2config"
)
View Source
const (
	BeegoSessionCookieNameCfgVar  string = "sessioncookiename"
	BeegoSessionCookieNameDefault string = "gosessionid"
	BeegoSessionProviderCfgVar    string = "sessionprovidername"
	BeegoSessionProviderDefault   string = "memory"
)

Variables

This section is empty.

Functions

func InitOAuth2Config

func InitOAuth2Config(o2ConfigSet *ms.ConfigMoreSet) error

func InitSession

func InitSession(sessionProvider string, sessionConfig *session.ManagerConfig, log *BeegoLogsMore)

InitSession creates a starts session management https://beego.me/docs/module/session.md

func NewLoggerAdapterConsole

func NewLoggerAdapterConsole() *logs.BeeLogger

func ProcErrPg

func ProcErrPg(err error) error

ProcErrPg removes the "no LastInsertId available" error. See more here: https://github.com/astaxie/beego/issues/3070 .

func WriteHtml

func WriteHtml(rw http.ResponseWriter, html []byte) (int, error)

Types

type BeegoLogsMore

type BeegoLogsMore struct {
	Logger *logs.BeeLogger
}

func NewBeegoLogsMoreAdapterConsole

func NewBeegoLogsMoreAdapterConsole() *BeegoLogsMore

func (*BeegoLogsMore) Critical

func (lm *BeegoLogsMore) Critical(s string)

Critical outputs a warning log message

func (*BeegoLogsMore) Criticalf

func (lm *BeegoLogsMore) Criticalf(format string, a ...interface{})

Criticalf outputs a formatted warning log message

func (*BeegoLogsMore) Error

func (lm *BeegoLogsMore) Error(s string)

Error outputs an information log message

func (*BeegoLogsMore) Errorf

func (lm *BeegoLogsMore) Errorf(format string, a ...interface{})

Errorf outputs a formatted information log message

func (*BeegoLogsMore) Info

func (lm *BeegoLogsMore) Info(s string)

Info outputs an information log message

func (*BeegoLogsMore) Infof

func (lm *BeegoLogsMore) Infof(format string, a ...interface{})

Infof outputs a formatted information log message

func (*BeegoLogsMore) Warn

func (lm *BeegoLogsMore) Warn(s string)

Warn outputs a warning log message

func (*BeegoLogsMore) Warnf

func (lm *BeegoLogsMore) Warnf(format string, a ...interface{})

Warnf outputs a formatted warning log message

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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