A Beego example app to demo OAuth 2.0 using Google and Facebook.
The following are used in this example app:
- OAuth 2.0
- Rendering
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.
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.
- Clone the repo
- Install the dependencies
- Set up your
app.conf
file. - 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
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 |
App credentials are created an managed using the Google Developers Console. To create an app, do the following:
- Navigate to Google Developers Console
- Click "API Manager"
- Create / Select a Project
- Click "Credentials"
- Create / Select OAuth 2.0 client IDs for "Web application"
- Click "Download JSON"