diff --git a/cmd/token.go b/cmd/token.go index bebb5f45..a8a350a3 100644 --- a/cmd/token.go +++ b/cmd/token.go @@ -21,6 +21,7 @@ var validateToken string var overrideClientId string var tokenServerPort int var tokenServerIP string +var redirectHost string // loginCmd represents the login command var loginCmd = &cobra.Command{ @@ -37,8 +38,9 @@ func init() { loginCmd.Flags().StringVarP(&revokeToken, "revoke", "r", "", "Instead of generating a new token, revoke the one passed to this parameter.") loginCmd.Flags().StringVarP(&validateToken, "validate", "v", "", "Instead of generating a new token, validate the one passed to this parameter.") loginCmd.Flags().StringVar(&overrideClientId, "client-id", "", "Override/manually set client ID for token actions. By default client ID from CLI config will be used.") - loginCmd.Flags().StringVar(&tokenServerIP, "ip", "localhost", "Manually set the IP address to be binded to for the User Token web server.") + loginCmd.Flags().StringVar(&tokenServerIP, "ip", "", "Manually set the IP address to be bound to for the User Token web server.") loginCmd.Flags().IntVarP(&tokenServerPort, "port", "p", 3000, "Manually set the port to be used for the User Token web server.") + loginCmd.Flags().StringVar(&redirectHost, "redirect-host", "localhost", "Manually set the host to be used for the redirect URL") } func loginCmdRun(cmd *cobra.Command, args []string) error { @@ -46,7 +48,7 @@ func loginCmdRun(cmd *cobra.Command, args []string) error { clientSecret = viper.GetString("clientSecret") webserverPort := strconv.Itoa(tokenServerPort) - redirectURL := fmt.Sprintf("http://%v:%v", tokenServerIP, webserverPort) + redirectURL := fmt.Sprintf("http://%v:%v", redirectHost, webserverPort) if clientID == "" || clientSecret == "" { println("No Client ID or Secret found in configuration. Triggering configuration now.") @@ -76,7 +78,7 @@ func loginCmdRun(cmd *cobra.Command, args []string) error { p.URL = login.ValidateTokenURL r, err := login.ValidateCredentials(p) if err != nil { - return fmt.Errorf("Failed to validate: %v", err.Error()) + return fmt.Errorf("failed to validate: %v", err.Error()) } tokenType := "App Access Token" @@ -105,7 +107,7 @@ func loginCmdRun(cmd *cobra.Command, args []string) error { fmt.Println(white("- %v\n", s)) } } - } else if isUserToken == true { + } else if isUserToken { p.URL = login.UserCredentialsURL login.UserCredentialsLogin(p, tokenServerIP, webserverPort) } else { diff --git a/docs/token.md b/docs/token.md index 4be61388..2588bc4a 100644 --- a/docs/token.md +++ b/docs/token.md @@ -97,6 +97,14 @@ Access tokens can be revoked with: twitch token -r 0123456789abcdefghijABCDEFGHIJ ``` +## Alternate IP for User Token Webserver + +If you'd like to bind the webserver used for user tokens (`-u` flag), you can override it with the `--ip` flag. For example: + +``` +twitch token -u --ip 127.0.0.1" +``` + ## Alternate Port 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 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. +## Alternate Host + +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`. + +Example: + +``` +twitch token -u --redirect-host contoso.com +``` + +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. + + ## Errors 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. **Flags** -| Flag | Shorthand | Description | Example | Required? (Y/N) | -|----------------|-----------|-------------------------------------------------------------------------------------------------------|----------------------------------------------|-----------------| -| `--user-token` | `-u` | Whether to fetch a user token or not. Default is false. | `token -u` | N | -| `--scopes` | `-s` | The space separated scopes to use when getting a user token. | `-s "user:read:email user_read"` | N | -| `--revoke` | `-r` | Instead of generating a new token, revoke the one passed to this parameter. | `-r 0123456789abcdefghijABCDEFGHIJ` | N | -| `--port` | `-p` | Override/manually set the port for token actions. (The default is 3000) | `-p 3030` | N | -| `--client-id` | | Override/manually set client ID for token actions. By default client ID from CLI config will be used. | `--client-id uo6dggojyb8d6soh92zknwmi5ej1q2` | N | - +| Flag | Shorthand | Description | Example | Required? (Y/N) | +|-------------------|-----------|----------------------------------------------------------------------------------------------------------------|----------------------------------------------|-----------------| +| `--user-token` | `-u` | Whether to fetch a user token or not. Default is false. | `token -u` | N | +| `--scopes` | `-s` | The space separated scopes to use when getting a user token. | `-s "user:read:email user_read"` | N | +| `--revoke` | `-r` | Instead of generating a new token, revoke the one passed to this parameter. | `-r 0123456789abcdefghijABCDEFGHIJ` | N | +| `--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 | +| `--port` | `-p` | Override/manually set the port for token actions. (The default is 3000) | `-p 3030` | N | +| `--client-id` | | Override/manually set client ID for token actions. By default client ID from CLI config will be used. | `--client-id uo6dggojyb8d6soh92zknwmi5ej1q2` | N | +| `--redirect-host` | | Override/manually set the redirect host token actions. The default is `localhost` | `--redirect-host contoso.com` | N | ## Notes