Skip to content

Invalid Grant #6

@ghost

Description

I'm attempting to call NewPatreonClient() for as defined in the README and receiving this error:

panic: Get "https://api.patreon.com/oauth2/api/current_user": oauth2: cannot fetch token: 401 Unauthorized
Response: {"error": "invalid_grant"}

I did modify the NewPatreonClient() in the README slightly because it was throwing errors due to missing a return and NewClient method not referencing the package. Here's my code:

func NewPatreonClient() (*patreon.Client, error) {
	config := oauth2.Config{
		ClientID:     os.Getenv("PATREON_CLIENT_ID"),
		ClientSecret: os.Getenv("PATREON_CLIENT_SECRET"),
		Endpoint: oauth2.Endpoint{
			AuthURL:  AUTHORIZATION_URL,
			TokenURL: ACCESS_TOKEN_URL,
		},
		Scopes: []string{"users", "pledges-to-me", "my-campaign"},
	}

	token := oauth2.Token{
		AccessToken:  os.Getenv("PATREON_CREATOR_ACCESS_TOKEN"),
		RefreshToken: os.Getenv("PATREON_CREATOR_REFRESH_TOKEN"),
		// Must be non-nil, otherwise token will not be expired
		Expiry: time.Now().Add(-24 * time.Hour),
	}

	tc := config.Client(context.Background(), &token)

	client := patreon.NewClient(tc)
	user, err := client.FetchUser()
	if err != nil {
		panic(err)
	}

	fmt.Printf("%v\n", user)

	return client, nil
}

I'm using patreon-go.v1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions