POST
/
v1
/
oauth2
/
token
package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"github.com/polarsource/polar-go/models/operations"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Oauth2.Token(ctx, operations.CreateOauth2RequestTokenRequestBodyAuthorizationCodeTokenRequest(
        components.AuthorizationCodeTokenRequest{
            ClientID: "<id>",
            ClientSecret: "<value>",
            Code: "<value>",
            RedirectURI: "https://talkative-barracks.com",
        },
    ))
    if err != nil {
        log.Fatal(err)
    }
    if res.TokenResponse != nil {
        // handle response
    }
}
{
  "access_token": "<string>",
  "token_type": "<string>",
  "expires_in": 123,
  "refresh_token": "<string>",
  "scope": "<string>",
  "id_token": "<string>"
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/x-www-form-urlencoded
grant_type
string
required
Allowed value: "authorization_code"
client_id
string
required
client_secret
string
required
code
string
required
redirect_uri
string
required
Required string length: 1 - 2083

Response

200 - application/json
Successful Response
access_token
string
required
token_type
string
required
Allowed value: "Bearer"
expires_in
integer
required
refresh_token
string | null
required
scope
string
required
id_token
string
required

Was this page helpful?