Open and3rson opened 3 years ago
This PR implements Application Only OAuth (also known as "two-legged oauth").
This is NOT a breaking change and is fully backwards-compatible. Default behavior is unaffected.
This flow is activated with WithApplicationOnlyOAuth(o bool) option:
WithApplicationOnlyOAuth(o bool)
o == true
"golang.org/x/oauth2/clientcredentials"
o == false
"golang.org/x/oauth2"
See #18 for discussion: https://github.com/vartanbeno/go-reddit/issues/18#issuecomment-890094080
Usage example:
package main import ( "context" "fmt" "github.com/and3rson/go-reddit/v2/reddit" ) func main() { client, err := reddit.NewClient(reddit.Credentials{ ID: "your_client_id", Secret: "your_client_secret", }, reddit.WithUserAgent("my-application"), reddit.WithApplicationOnlyOAuth(true)) if err != nil { panic(err) } posts, err := client.Subreddit.TopPosts(context.Background(), "funny", &reddit.ListPostOptions{}) if err != nil { panic(err) } fmt.Println(posts) }
Unit test included.
This PR implements Application Only OAuth (also known as "two-legged oauth").
This is NOT a breaking change and is fully backwards-compatible. Default behavior is unaffected.
This flow is activated with
WithApplicationOnlyOAuth(o bool)
option:o == true
: oauthTransport uses"golang.org/x/oauth2/clientcredentials"
o == false
: oauthTransport uses"golang.org/x/oauth2"
(default behavior)See #18 for discussion: https://github.com/vartanbeno/go-reddit/issues/18#issuecomment-890094080
Usage example:
Unit test included.