Skip to content

Latest commit

 

History

History
283 lines (210 loc) · 13.8 KB

README.md

File metadata and controls

283 lines (210 loc) · 13.8 KB

Oauth2

(Oauth2)

Overview

Available Operations

Authorize

Authorize

Example Usage

package main

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

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

    res, err := s.Oauth2.Authorize(ctx)
    if err != nil {
        log.Fatal(err)
    }
    if res.ResponseOauth2Authorize != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
opts []operations.Option The options for this request.

Response

*operations.Oauth2AuthorizeResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

Token

Request an access token using a valid grant.

Example Usage

package main

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

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

    res, err := s.Oauth2.Token(ctx, operations.CreateOauth2RequestTokenRequestBodyOnev11oauth21tokenPostXComponentsAuthorizationCodeTokenRequest(
        components.Onev11oauth21tokenPostXComponentsAuthorizationCodeTokenRequest{
            ClientID: "<id>",
            ClientSecret: "<value>",
            Code: "<value>",
            RedirectURI: "https://talkative-barracks.com",
        },
    ))
    if err != nil {
        log.Fatal(err)
    }
    if res.TokenResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.Oauth2RequestTokenRequestBody ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.Oauth2RequestTokenResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

Revoke

Revoke an access token or a refresh token.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"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.Revoke(ctx, operations.Oauth2RevokeTokenRevokeTokenRequest{
        Token: "<value>",
        ClientID: "<id>",
        ClientSecret: "<value>",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.RevokeTokenResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.Oauth2RevokeTokenRevokeTokenRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.Oauth2RevokeTokenResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

Introspect

Get information about an access token.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"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.Introspect(ctx, operations.Oauth2IntrospectTokenIntrospectTokenRequest{
        Token: "<value>",
        ClientID: "<id>",
        ClientSecret: "<value>",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.IntrospectTokenResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.Oauth2IntrospectTokenIntrospectTokenRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.Oauth2IntrospectTokenResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*

Userinfo

Get information about the authenticated user.

Example Usage

package main

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

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

    res, err := s.Oauth2.Userinfo(ctx)
    if err != nil {
        log.Fatal(err)
    }
    if res.ResponseOauth2Userinfo != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
opts []operations.Option The options for this request.

Response

*operations.Oauth2UserinfoResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*