Skip to content

Commit 3f840ac

Browse files
authored
Merge branch 'main' into fix/103
2 parents 7a7cb4a + 11a468d commit 3f840ac

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

cmd/configure.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func configureCmdRun(cmd *cobra.Command, args []string) error {
7373
}
7474

7575
if err := viper.WriteConfigAs(configPath); err != nil {
76-
fmt.Errorf("Failed to write configuration: %v", err.Error())
76+
return fmt.Errorf("Failed to write configuration: %v", err.Error())
7777
}
7878

7979
fmt.Println("Updated configuration.")

cmd/events.go

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event`
321321
Timestamp: timestamp,
322322
EventID: eventID,
323323
BroadcasterUserID: toUser,
324+
Version: version,
324325
})
325326

326327
if err != nil {

cmd/token.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var validateToken string
2121
var overrideClientId string
2222
var tokenServerPort int
2323
var tokenServerIP string
24+
var redirectHost string
2425

2526
// loginCmd represents the login command
2627
var loginCmd = &cobra.Command{
@@ -37,20 +38,25 @@ func init() {
3738
loginCmd.Flags().StringVarP(&revokeToken, "revoke", "r", "", "Instead of generating a new token, revoke the one passed to this parameter.")
3839
loginCmd.Flags().StringVarP(&validateToken, "validate", "v", "", "Instead of generating a new token, validate the one passed to this parameter.")
3940
loginCmd.Flags().StringVar(&overrideClientId, "client-id", "", "Override/manually set client ID for token actions. By default client ID from CLI config will be used.")
40-
loginCmd.Flags().StringVar(&tokenServerIP, "ip", "localhost", "Manually set the IP address to be binded to for the User Token web server.")
41+
loginCmd.Flags().StringVar(&tokenServerIP, "ip", "", "Manually set the IP address to be bound to for the User Token web server.")
4142
loginCmd.Flags().IntVarP(&tokenServerPort, "port", "p", 3000, "Manually set the port to be used for the User Token web server.")
43+
loginCmd.Flags().StringVar(&redirectHost, "redirect-host", "localhost", "Manually set the host to be used for the redirect URL")
4244
}
4345

4446
func loginCmdRun(cmd *cobra.Command, args []string) error {
4547
clientID = viper.GetString("clientId")
4648
clientSecret = viper.GetString("clientSecret")
4749

4850
webserverPort := strconv.Itoa(tokenServerPort)
49-
redirectURL := fmt.Sprintf("http://%v:%v", tokenServerIP, webserverPort)
51+
redirectURL := fmt.Sprintf("http://%v:%v", redirectHost, webserverPort)
5052

5153
if clientID == "" || clientSecret == "" {
5254
println("No Client ID or Secret found in configuration. Triggering configuration now.")
53-
configureCmd.Run(cmd, args)
55+
err := configureCmd.RunE(cmd, args)
56+
if err != nil {
57+
return err
58+
}
59+
5460
clientID = viper.GetString("clientId")
5561
clientSecret = viper.GetString("clientSecret")
5662
}
@@ -76,7 +82,7 @@ func loginCmdRun(cmd *cobra.Command, args []string) error {
7682
p.URL = login.ValidateTokenURL
7783
r, err := login.ValidateCredentials(p)
7884
if err != nil {
79-
return fmt.Errorf("Failed to validate: %v", err.Error())
85+
return fmt.Errorf("failed to validate: %v", err.Error())
8086
}
8187

8288
tokenType := "App Access Token"
@@ -105,7 +111,7 @@ func loginCmdRun(cmd *cobra.Command, args []string) error {
105111
fmt.Println(white("- %v\n", s))
106112
}
107113
}
108-
} else if isUserToken == true {
114+
} else if isUserToken {
109115
p.URL = login.UserCredentialsURL
110116
login.UserCredentialsLogin(p, tokenServerIP, webserverPort)
111117
} else {

docs/token.md

+30-8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ Access tokens can be revoked with:
9797
twitch token -r 0123456789abcdefghijABCDEFGHIJ
9898
```
9999

100+
## Alternate IP for User Token Webserver
101+
102+
If you'd like to bind the webserver used for user tokens (`-u` flag), you can override it with the `--ip` flag. For example:
103+
104+
```
105+
twitch token -u --ip 127.0.0.1"
106+
```
107+
100108
## Alternate Port
101109

102110
Port 3000 on localhost is used by default when fetching User Access Tokens. The `-p` flag can be used to change to another port if another service is already occupying that port. For example:
@@ -108,6 +116,19 @@ twitch token -u -p 3030 -s "moderator:manage:shoutouts moderator:manage:shield_m
108116
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.
109117

110118

119+
## Alternate Host
120+
121+
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`.
122+
123+
Example:
124+
125+
```
126+
twitch token -u --redirect-host contoso.com
127+
```
128+
129+
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.
130+
131+
111132
## Errors
112133

113134
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)
@@ -126,14 +147,15 @@ None.
126147

127148
**Flags**
128149

129-
| Flag | Shorthand | Description | Example | Required? (Y/N) |
130-
|----------------|-----------|-------------------------------------------------------------------------------------------------------|----------------------------------------------|-----------------|
131-
| `--user-token` | `-u` | Whether to fetch a user token or not. Default is false. | `token -u` | N |
132-
| `--scopes` | `-s` | The space separated scopes to use when getting a user token. | `-s "user:read:email user_read"` | N |
133-
| `--revoke` | `-r` | Instead of generating a new token, revoke the one passed to this parameter. | `-r 0123456789abcdefghijABCDEFGHIJ` | N |
134-
| `--port` | `-p` | Override/manually set the port for token actions. (The default is 3000) | `-p 3030` | N |
135-
| `--client-id` | | Override/manually set client ID for token actions. By default client ID from CLI config will be used. | `--client-id uo6dggojyb8d6soh92zknwmi5ej1q2` | N |
136-
150+
| Flag | Shorthand | Description | Example | Required? (Y/N) |
151+
|-------------------|-----------|----------------------------------------------------------------------------------------------------------------|----------------------------------------------|-----------------|
152+
| `--user-token` | `-u` | Whether to fetch a user token or not. Default is false. | `token -u` | N |
153+
| `--scopes` | `-s` | The space separated scopes to use when getting a user token. | `-s "user:read:email user_read"` | N |
154+
| `--revoke` | `-r` | Instead of generating a new token, revoke the one passed to this parameter. | `-r 0123456789abcdefghijABCDEFGHIJ` | N |
155+
| `--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 |
156+
| `--port` | `-p` | Override/manually set the port for token actions. (The default is 3000) | `-p 3030` | N |
157+
| `--client-id` | | Override/manually set client ID for token actions. By default client ID from CLI config will be used. | `--client-id uo6dggojyb8d6soh92zknwmi5ej1q2` | N |
158+
| `--redirect-host` | | Override/manually set the redirect host token actions. The default is `localhost` | `--redirect-host contoso.com` | N |
137159

138160
## Notes
139161

0 commit comments

Comments
 (0)