Skip to main content

OAuth2 for Go integration

This quickstart guide covers the essential steps to start integrating Pangea AuthN in a golang/oauth2 application.

Create an OAuth client

Create a new OAuth client as described in OAuth Server with the following parameters:

  • Grant Types: Authorization Code
  • Response Types: Code, Token
  • Allowed Scopes: openid, profile, email
  • Default scopes: openid, profile, email

Note down the client ID (starts with "psa_") and client secret (starts with "pck_") for later.

Set up provider

package main

import (
"context"
"fmt"
"log"

"golang.org/x/oauth2"
)

func main() {
ctx := context.Background()

conf := &oauth2.Config{
ClientID: "psa_000000",
ClientSecret: "pck_111111",
RedirectURL: "https://example.org/callback",
Scopes: []string{
"openid",
"profile",
"email",
},
Endpoint: oauth2.Endpoint{
AuthURL: "https://pdn-222222.login.aws.us.pangea.cloud/v1beta/oauth/authorize",
TokenURL: "https://pdn-222222.login.aws.us.pangea.cloud/v1beta/oauth/token",
},
}

// Redirect user to Pangea AuthN.
url := conf.AuthCodeURL("random-state-value")
fmt.Printf("Visit the URL for the auth dialog: %v", url)

// ...

// Exchange the authorization code for a token.
token, err := conf.Exchange(ctx, "authorization-code-from-previous-step")
if err != nil {
log.Fatal(err)
}
}

Was this article helpful?

Contact us