Go

By Andres Aguiar

Sample Project

Before you start

This guide walks you through setting up authentication and authorization in your Go apps with Auth0. If you are new to Auth0 we suggest you check our Overview. For a complete picture of authentication and authorization for regular web apps, check our Single Sign-On for Regular Web Apps documentation.

Get Your Application Keys

You will need some details about this application to communicate with Auth0. You can get them from the Application Settings in the Auth0 dashboard.

You need the following information:

Client ID

Domain

If you download the sample from the top of this page, these details are filled out for you. If you have more than one application in your account, the sample comes with the values for your Default App.

Configure Callback URLs

A callback URL is a URL in your application where Auth0 redirects the user after they have authenticated.

You need to whitelist the callback URL for your app in the Allowed Callback URLs field in your Application Settings. If you do not set any callback URL, your users will see a mismatch error when they log in.

If you are following along with the sample project you downloaded from the top of this page, Callback URL should be set to
http://localhost:3000.

Add Dependencies

Install the following dependencies using go get.

go get github.com/gorilla/mux
go get github.com/gorilla/sessions
go get golang.org/x/oauth2

Did it help?/

This example uses mux for routing but you can use whichever router you want.

Add the Auth0 Callback Handler

You'll need to create a callback handler that Auth0 will call once it redirects to your app. For that, you can do the following: