|  | @@ -23,6 +23,8 @@ import (
 | 
	
		
			
				|  |  |  	"math/rand"
 | 
	
		
			
				|  |  |  	"net/http"
 | 
	
		
			
				|  |  |  	"net/url"
 | 
	
		
			
				|  |  | +	"os/exec"
 | 
	
		
			
				|  |  | +	"runtime"
 | 
	
		
			
				|  |  |  	"strings"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	"github.com/pkg/errors"
 | 
	
	
		
			
				|  | @@ -30,16 +32,16 @@ import (
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  type apiHelper interface {
 | 
	
		
			
				|  |  |  	queryToken(data url.Values, tenantID string) (azureToken, error)
 | 
	
		
			
				|  |  | -	openAzureLoginPage(redirectURL string)
 | 
	
		
			
				|  |  | +	openAzureLoginPage(redirectURL string) error
 | 
	
		
			
				|  |  |  	queryAuthorizationAPI(authorizationURL string, authorizationHeader string) ([]byte, int, error)
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  type azureAPIHelper struct{}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func (helper azureAPIHelper) openAzureLoginPage(redirectURL string) {
 | 
	
		
			
				|  |  | +func (helper azureAPIHelper) openAzureLoginPage(redirectURL string) error {
 | 
	
		
			
				|  |  |  	state := randomString("", 10)
 | 
	
		
			
				|  |  |  	authURL := fmt.Sprintf(authorizeFormat, clientID, redirectURL, state, scopes)
 | 
	
		
			
				|  |  | -	openbrowser(authURL)
 | 
	
		
			
				|  |  | +	return openbrowser(authURL)
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func (helper azureAPIHelper) queryAuthorizationAPI(authorizationURL string, authorizationHeader string) ([]byte, int, error) {
 | 
	
	
		
			
				|  | @@ -78,6 +80,19 @@ func (helper azureAPIHelper) queryToken(data url.Values, tenantID string) (azure
 | 
	
		
			
				|  |  |  	return token, nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +func openbrowser(url string) error {
 | 
	
		
			
				|  |  | +	switch runtime.GOOS {
 | 
	
		
			
				|  |  | +	case "linux":
 | 
	
		
			
				|  |  | +		return exec.Command("xdg-open", url).Start()
 | 
	
		
			
				|  |  | +	case "windows":
 | 
	
		
			
				|  |  | +		return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
 | 
	
		
			
				|  |  | +	case "darwin":
 | 
	
		
			
				|  |  | +		return exec.Command("open", url).Start()
 | 
	
		
			
				|  |  | +	default:
 | 
	
		
			
				|  |  | +		return fmt.Errorf("unsupported platform")
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  var (
 | 
	
		
			
				|  |  |  	letterRunes = []rune("abcdefghijklmnopqrstuvwxyz123456789")
 | 
	
		
			
				|  |  |  )
 |