Skip to content

Commit 83ccfff

Browse files
authored
Merge pull request #337 from BarryCarlyon/authForceVerify
Auth force verify
2 parents 52b9ef9 + 21f3859 commit 83ccfff

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

cmd/token.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
var isUserToken bool
1919
var userScopes string
20+
var forceVerify bool
2021
var revokeToken string
2122
var validateToken string
2223
var refreshToken string
@@ -39,6 +40,7 @@ func init() {
3940

4041
loginCmd.Flags().BoolVarP(&isUserToken, "user-token", "u", false, "Whether to login as a user or getting an app access token.")
4142
loginCmd.Flags().StringVarP(&userScopes, "scopes", "s", "", "Space separated list of scopes to request with your user token.")
43+
loginCmd.Flags().BoolVar(&forceVerify, "forceverify", false, "Set Force Verify")
4244
loginCmd.Flags().StringVarP(&revokeToken, "revoke", "r", "", "Instead of generating a new token, revoke the one passed to this parameter.")
4345
loginCmd.Flags().StringVarP(&validateToken, "validate", "v", "", "Instead of generating a new token, validate the one passed to this parameter.")
4446
loginCmd.Flags().StringVarP(&refreshToken, "refresh", "R", "", "Instead of generating a new token, refresh the token associated with the Refresh Token passed to this parameter.")
@@ -76,10 +78,16 @@ func loginCmdRun(cmd *cobra.Command, args []string) error {
7678
clientSecret = overrideClientSecret
7779
}
7880

81+
forceVerifyWord := "false"
82+
if forceVerify {
83+
forceVerifyWord = "true"
84+
}
85+
7986
var p = login.LoginParameters{
8087
ClientID: clientID,
8188
ClientSecret: clientSecret,
8289
Scopes: userScopes,
90+
ForceVerify: forceVerifyWord,
8391
RedirectURL: redirectURL,
8492
AuthorizeURL: login.UserAuthorizeURL,
8593
}

docs/token.md

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ The `token` product is used to fetch access tokens for an application
66

77
## Token Types
88

9-
The Twitch CLI provides access to two types of tokens: App Access Tokens and User Access Tokens.
9+
The Twitch CLI provides access to two types of tokens: App Access Tokens and User Access Tokens.
1010

11-
**App Access Tokens**
11+
**App Access Tokens**
1212

13-
[App Access Tokens](https://dev.twitch.tv/docs/authentication/#app-access-tokens) can access APIs that don't require the user's permission. For example, getting a list of videos.
13+
[App Access Tokens](https://dev.twitch.tv/docs/authentication/#app-access-tokens) can access APIs that don't require the user's permission. For example, getting a list of videos.
1414

15-
**User Access Tokens**
15+
**User Access Tokens**
1616

1717
[User Access Tokens](https://dev.twitch.tv/docs/authentication/#user-access-tokens) provide access to APIs a user must grant permission to. For example, starting or stopping a poll. The specific APIs and functionality granted to a token is defined via [scopes](https://dev.twitch.tv/docs/authentication/scopes/).
1818

1919
## Client IDs and Client Secrets
2020

21-
Getting Access Tokens requires use of a Client ID and Client Secret which are associated with a Twitch Developer's Application. Creating an application is done by registration. Details on that process [are here](https://dev.twitch.tv/docs/authentication/register-app/). Client IDs are generated automatically when an application is registered. Client Secrets must be generated explicitly. This can be done by visiting [the Developer Applications Console](https://dev.twitch.tv/console/apps), choosing "Manage" for the app, then using the "New Secret" button at the bottom of the page.
21+
Getting Access Tokens requires use of a Client ID and Client Secret which are associated with a Twitch Developer's Application. Creating an application is done by registration. Details on that process [are here](https://dev.twitch.tv/docs/authentication/register-app/). Client IDs are generated automatically when an application is registered. Client Secrets must be generated explicitly. This can be done by visiting [the Developer Applications Console](https://dev.twitch.tv/console/apps), choosing "Manage" for the app, then using the "New Secret" button at the bottom of the page.
2222

2323
Adding the Client ID and Client Secret to the CLI tool is done with:
2424

2525
```
2626
twitch configure
2727
```
2828

29-
Running that starts prompts asking for the credentials.
29+
Running that starts prompts asking for the credentials.
3030

3131
## Fetching App Access Tokens
3232

@@ -42,7 +42,6 @@ Running that returns a result with the token like:
4242
2023/08/23 13:19:08 App Access Token: 01234abcdetc...
4343
```
4444

45-
4645
## Fetching User Access Tokens
4746

4847
Fetching User Access Tokens requires setting an _OAuth Redirect URL_. Those URLs are defined on the _Manage_ page for each app in the [Developer's Application Console](https://dev.twitch.tv/console/apps). The twitch CLI uses `http://localhost:3000`. Two important notes when adding that to the OAuth Redirect URLs section:
@@ -52,12 +51,11 @@ Fetching User Access Tokens requires setting an _OAuth Redirect URL_. Those URLs
5251

5352
**The User Flag**
5453

55-
The `-u` flag is what sets the `token` product to fetch a User Access Token instead of an App Access Token.
56-
54+
The `-u` flag is what sets the `token` product to fetch a User Access Token instead of an App Access Token.
5755

5856
**Scopes**
5957

60-
User Access Tokens use scopes to determine which APIs and features they have access to. The requested scopes are defined via a space separated list following an `-s` flag with the `token` product.
58+
User Access Tokens use scopes to determine which APIs and features they have access to. The requested scopes are defined via a space separated list following an `-s` flag with the `token` product.
6159

6260
The full list of available scopes [here in the Twitch Documentation](https://dev.twitch.tv/docs/authentication/scopes/)
6361

@@ -69,7 +67,7 @@ A full example fetching a User Access Token with the ability to do shoutouts and
6967
twitch token -u -s "moderator:manage:shoutouts moderator:manage:shield_mode"
7068
```
7169

72-
Running that produce some initial output in the terminal and opens a browser to a Twitch authorization page. If you're not already signed in, you'll be asked to do so. When signed-in, the page displays the authorization request including the requested scopes. Clicking the "Authorize" button at the bottom redirects the browser back to the `http://localhost:3000` address where the `twitch` CLI picks it up and complete the process by parsing the data returned in the URL.
70+
Running that produce some initial output in the terminal and opens a browser to a Twitch authorization page. If you're not already signed in, you'll be asked to do so. When signed-in, the page displays the authorization request including the requested scopes. Clicking the "Authorize" button at the bottom redirects the browser back to the `http://localhost:3000` address where the `twitch` CLI picks it up and complete the process by parsing the data returned in the URL.
7371

7472
The browser will display a message like:
7573

@@ -140,6 +138,7 @@ By default, this uses the Client ID and Client Secret stored in your config file
140138
```
141139
twitch token --refresh ABCDEfghij0123456789abcdefghijABCDEFGHIJ --client-id uo6dggojyb8d6soh92zknwmi5ej1q2 --secret yigv8zib6nuczcoy08u8g1nxh6wjgu
142140
```
141+
143142
When overriding the Client ID, your config file will **not** be updated with the new access token, client ID, or secret.
144143

145144
## Alternate IP for User Token Webserver
@@ -160,20 +159,18 @@ twitch token -u -p 3030 -s "moderator:manage:shoutouts moderator:manage:shield_m
160159

161160
NOTE: You must update the first entry in the _OAuth Redirect URLs_ section of your app's management page in the [Developer's Application Console](https://dev.twitch.tv/console/apps) to match the new port number. Make sure there is no `/` at the end of the URL (e.g. use `http://localhost:3030` and not `http://localhost:3030/`) and that the URL is the first entry in the list if there is more than one.
162161

163-
164162
## Alternate Host
165163

166164
If you'd like to change the hostname for one reason or another (e.g. binding to a local domain), you can use the `--redirect-host` to change the domain. You should _not_ prefix it with `http` or `https`.
167165

168-
Example:
166+
Example:
169167

170168
```
171169
twitch token -u --redirect-host contoso.com
172170
```
173171

174172
NOTE: You must update the first entry in the _OAuth Redirect URLs_ section of your app's management page in the [Developer's Application Console](https://dev.twitch.tv/console/apps) to match the new port number. Make sure there is no `/` at the end of the URL (e.g. use `http://localhost:3030` and not `http://localhost:3030/`) and that the URL is the first entry in the list if there is more than one.
175173

176-
177174
## Errors
178175

179176
This error occurs when there's a problem with the OAuth Redirect URLs. Check in the app's management page in the [Developer's Application Console](https://dev.twitch.tv/console/apps) to ensure the first entry is set to `http://localhost:3000`. Specifically, verify that your using `http` and not `https` and that the URL does not end with a `/`. (If you've changed ports with the `-p` flag, ensure those numbers match as well)
@@ -189,24 +186,24 @@ Error Details: Parameter redirect_uri does not match registered URI
189186

190187
None.
191188

192-
193189
**Flags**
194190

195-
| Flag | Shorthand | Description | Example | Required? (Y/N) |
196-
|-------------------|-----------|------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|-----------------|
197-
| `--user-token` | `-u` | Whether to fetch a user token or not. Default is false. | `token -u` | N |
198-
| `--dcf` | | Uses Device Code Flow for your User Access Token. Can only be used with --user-token | `token -u --dcf` | N |
199-
| `--scopes` | `-s` | The space separated scopes to use when getting a user token. | `-s "user:read:email user_read"` | N |
200-
| `--revoke` | `-r` | Instead of generating a new token, revoke the one passed to this parameter. | `-r 0123456789abcdefghijABCDEFGHIJ` | N |
201-
| `--validate` | `-v` | Instead of generating a new token, validate the one passed to this parameter. | `-v 0123456789abcdefghijABCDEFGHIJ` | N |
202-
| `--refresh` | `-R` | Instead of generating a new token, refresh the token associated with the Refresh Token passed to this parameter. | `-R ABCDEfghij0123456789abcdefghijABCDEFGHIJ` | N |
203-
| `--ip` | | Manually set the port to be used for the User Token web server. The default binds to all interfaces. (0.0.0.0) | `--ip 127.0.0.1` | N |
204-
| `--port` | `-p` | Override/manually set the port for token actions. (The default is 3000) | `-p 3030` | N |
205-
| `--client-id` | | Override/manually set Client ID for token actions. By default Client ID from CLI config will be used. | `--client-id uo6dggojyb8d6soh92zknwmi5ej1q2` | N |
206-
| `--secret` | | Override/manually set Client Secret for token actions. By default Client Secret from CLI config will be used. | `--secret yigv8zib6nuczcoy08u8g1nxh6wjgu` | N |
207-
| `--redirect-host` | | Override/manually set the redirect host token actions. The default is `localhost` | `--redirect-host contoso.com` | N |
191+
| Flag | Shorthand | Description | Example | Required? (Y/N) |
192+
| ----------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- | --------------- |
193+
| `--user-token` | `-u` | Whether to fetch a user token or not. Default is false. | `token -u` | N |
194+
| `--dcf` | | Uses Device Code Flow for your User Access Token. Can only be used with --user-token | `token -u --dcf` | N |
195+
| `--forceverify` | | Sets `force_verify` to true, so you can check scopes and which account you are authing as. Can only be used with --user-token | `token -u --forceverify` | N |
196+
| `--scopes` | `-s` | The space separated scopes to use when getting a user token. | `-s "user:read:email user_read"` | N |
197+
| `--revoke` | `-r` | Instead of generating a new token, revoke the one passed to this parameter. | `-r 0123456789abcdefghijABCDEFGHIJ` | N |
198+
| `--validate` | `-v` | Instead of generating a new token, validate the one passed to this parameter. | `-v 0123456789abcdefghijABCDEFGHIJ` | N |
199+
| `--refresh` | `-R` | Instead of generating a new token, refresh the token associated with the Refresh Token passed to this parameter. | `-R ABCDEfghij0123456789abcdefghijABCDEFGHIJ` | N |
200+
| `--ip` | | Manually set the port to be used for the User Token web server. The default binds to all interfaces. (0.0.0.0) | `--ip 127.0.0.1` | N |
201+
| `--port` | `-p` | Override/manually set the port for token actions. (The default is 3000) | `-p 3030` | N |
202+
| `--client-id` | | Override/manually set Client ID for token actions. By default Client ID from CLI config will be used. | `--client-id uo6dggojyb8d6soh92zknwmi5ej1q2` | N |
203+
| `--secret` | | Override/manually set Client Secret for token actions. By default Client Secret from CLI config will be used. | `--secret yigv8zib6nuczcoy08u8g1nxh6wjgu` | N |
204+
| `--redirect-host` | | Override/manually set the redirect host token actions. The default is `localhost` | `--redirect-host contoso.com` | N |
208205

209206
## Notes
210207

211-
- If you've already authorized the app, the webpage will redirect back immediately without requiring any interaction
212-
- You'll be asked to fill in the Client ID and Client Secret if you run the `token` product without having already set them
208+
- If you've already authorized the app, the webpage will redirect back immediately without requiring any interaction
209+
- You'll be asked to fill in the Client ID and Client Secret if you run the `token` product without having already set them

internal/login/login.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type LoginParameters struct {
2626
ClientID string
2727
ClientSecret string
2828
Scopes string
29+
ForceVerify string
2930
Token string
3031
URL string
3132
RedirectURL string
@@ -130,6 +131,9 @@ func UserCredentialsLogin_AuthorizationCodeFlow(p LoginParameters, webserverIP s
130131
if p.Scopes != "" {
131132
q.Set("scope", p.Scopes)
132133
}
134+
if p.ForceVerify != "" {
135+
q.Set("force_verify", p.ForceVerify)
136+
}
133137

134138
state, err := generateState()
135139
if err != nil {

0 commit comments

Comments
 (0)