1# Authentication Documentation 2 3## Get Authorization URL 4 5The below `GetAuthorizationURL` method returns a URL, based on your Client ID, redirect URI, and scopes, that can be used to authenticate users with their Twitch accounts. After the user authorizes your application, they will be redirected to the provided redirect URI with an authorization code that can be used to generate access tokens for API consumption. See the Twitch [authentication docs](https://dev.twitch.tv/docs/authentication) for more information. 6 7```go 8client, err := helix.NewClient(&helix.Options{ 9 ClientID: "your-client-id", 10 RedirectURI: "https://example.com/auth/callback", 11 Scopes: []string{"analytics:read:games", "bits:read", "clips:edit", "user:edit", "user:read:email"}, 12}) 13if err != nil { 14 // handle error 15} 16 17url := client.GetAuthorizationURL("your-state", true) 18 19fmt.Printf("%s\n", url) 20``` 21 22## Get App Access Token 23 24Here's an example of how to create an app access token: 25 26```go 27client, err := helix.NewClient(&helix.Options{ 28 ClientID: "your-client-id", 29 ClientSecret: "your-client-secret", 30}) 31if err != nil { 32 // handle error 33} 34 35resp, err := client.GetAppAccessToken() 36if err != nil { 37 // handle error 38} 39 40fmt.Printf("%+v\n", resp) 41``` 42 43## Get User Access Token 44 45After obtaining an authentication code, you can submit a request for a user access token which can then be used to submit API requests on behalf of a user. Here's an example of how to create a user access token: 46 47```go 48client, err := helix.NewClient(&helix.Options{ 49 ClientID: "your-client-id", 50 ClientSecret: "your-client-secret", 51 RedirectURI: "https://example.com/auth/callback", 52}) 53if err != nil { 54 // handle error 55} 56 57code := "your-authentication-code" 58 59resp, err := client.GetUserAccessToken(code) 60if err != nil { 61 // handle error 62} 63 64fmt.Printf("%+v\n", resp) 65``` 66 67## Refresh User Access Token 68 69You can refresh a user access token in the following manner: 70 71```go 72client, err := helix.NewClient(&helix.Options{ 73 ClientID: "your-client-id", 74 ClientSecret: "your-client-secret", 75}) 76if err != nil { 77 // handle error 78} 79 80refreshToken := "your-refresh-token" 81 82resp, err := client.RefreshUserAccessToken(refreshToken) 83if err != nil { 84 // handle error 85} 86 87fmt.Printf("%+v\n", resp) 88``` 89 90## Revoke User Access Token 91 92You can revoke a user access token in the following manner: 93 94```go 95client, err := helix.NewClient(&helix.Options{ 96 ClientID: "your-client-id", 97}) 98if err != nil { 99 // handle error 100} 101 102userAccessToken := "your-user-access-token-to-revoke" 103 104resp, err := client.RevokeUserAccessToken(userAccessToken) 105if err != nil { 106 // handle error 107} 108 109fmt.Printf("%+v\n", resp) 110``` 111