diff --git a/auth/auth.go b/auth/auth.go index c6018f420..549729a5b 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -48,14 +48,7 @@ func getWorkspaceByLabel(label string) *houston.Workspace { func oAuth(oAuthUrl string) string { fmt.Println("\n" + messages.HOUSTON_OAUTH_REDIRECT) fmt.Println(oAuthUrl + "\n") - authSecret := input.InputText(messages.INPUT_OAUTH_TOKEN) - - token, err := api.CreateOAuthToken(authSecret) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - return token.Token.Value + return input.InputText(messages.INPUT_OAUTH_TOKEN) } // registryAuth authenticates with the private registry @@ -112,13 +105,13 @@ func Login(domain string, oAuthOnly bool) error { } username := "" - if !oAuthOnly { + if !oAuthOnly && authConfig.LocalEnabled { username = input.InputText(messages.INPUT_USERNAME) } if len(username) == 0 { - if authConfig.GoogleEnabled { - token = oAuth(authConfig.OauthUrl) + if authConfig.GoogleEnabled || authConfig.Auth0Enabled || authConfig.GithubEnabled { + token = oAuth(c.GetAppURL() + "/login?source=cli") } else { fmt.Println(messages.HOUSTON_OAUTH_DISABLED) os.Exit(1) @@ -131,10 +124,6 @@ func Login(domain string, oAuthOnly bool) error { } } - c, err = cluster.GetCluster(domain) - if err != nil { - return err - } c.SetContextKey("token", token) // Attempt to set projectworkspace if there is only one workspace diff --git a/config/config.go b/config/config.go index 0ddb94922..607ae30a5 100644 --- a/config/config.go +++ b/config/config.go @@ -41,7 +41,9 @@ var ( CloudAPIPort: newCfg("cloud.api.port", "443"), CloudAPIToken: newCfg("cloud.api.token", ""), Context: newCfg("context", ""), - LocalAPIURL: newCfg("local.api.url", ""), + LocalEnabled: newCfg("local.enabled", ""), + LocalHouston: newCfg("local.houston", ""), + LocalOrbit: newCfg("local.orbit", ""), PostgresUser: newCfg("postgres.user", "postgres"), PostgresPassword: newCfg("postgres.password", "postgres"), PostgresHost: newCfg("postgres.host", "postgres"), diff --git a/config/context.go b/config/context.go index 13863ee4f..5c1b447fb 100644 --- a/config/context.go +++ b/config/context.go @@ -168,6 +168,9 @@ func (c Context) SwitchContext() error { // GetAPIURL returns full Houston API Url for the provided Context func (c Context) GetAPIURL() string { + if len(CFG.LocalEnabled.GetString()) != 0 { + return CFG.LocalHouston.GetString() + } return fmt.Sprintf( "%s://houston.%s:%s/v1", CFG.CloudAPIProtocol.GetString(), @@ -175,3 +178,15 @@ func (c Context) GetAPIURL() string { CFG.CloudAPIPort.GetString(), ) } + +// GetAppURL returns full Houston API Url for the provided Context +func (c Context) GetAppURL() string { + if len(CFG.LocalEnabled.GetString()) != 0 { + return CFG.LocalOrbit.GetString() + } + return fmt.Sprintf( + "%s://app.%s", + CFG.CloudAPIProtocol.GetString(), + c.Domain, + ) +} diff --git a/config/types.go b/config/types.go index 3610c97ff..714ea1378 100644 --- a/config/types.go +++ b/config/types.go @@ -13,7 +13,9 @@ type cfgs struct { CloudAPIPort cfg CloudAPIToken cfg Context cfg - LocalAPIURL cfg + LocalEnabled cfg + LocalHouston cfg + LocalOrbit cfg PostgresUser cfg PostgresPassword cfg PostgresHost cfg diff --git a/houston/houston.go b/houston/houston.go index 71e0956f6..813e9a3f7 100644 --- a/houston/houston.go +++ b/houston/houston.go @@ -17,9 +17,11 @@ import ( var ( authConfigGetRequest = ` query GetAuthConfig { - authConfig(state: "cli") { + authConfig(redirect: "") { localEnabled googleEnabled + githubEnabled + auth0Enabled googleOAuthUrl } }` @@ -102,9 +104,8 @@ var ( tokenBasicCreateRequest = ` mutation createBasicToken { createToken( - authStrategy:LOCAL identity:"%s", - credentials:"%s" + password:"%s" ) { user { uuid @@ -119,18 +120,6 @@ var ( } }` - tokenOAuthCreateRequest = ` - mutation createOauthBasicToken { - createToken( - authStrategy:%s - credentials:"%s" - ) { - token { - value - } - } - }` - userCreateRequest = ` mutation CreateUser { createUser( @@ -365,19 +354,6 @@ func (c *Client) CreateBasicToken(email, password string) (*AuthUser, error) { return response.Data.CreateToken, nil } -// CreateOAuthToken passes an OAuth type and authCode to createOauthTokenRequest in order allow houston to authenticate user -// Returns a Token structure with the users ID and Token inside. -func (c *Client) CreateOAuthToken(authCode string) (*AuthUser, error) { - request := fmt.Sprintf(tokenOAuthCreateRequest, "GOOGLE_OAUTH", authCode) - - response, err := c.QueryHouston(request) - if err != nil { - return nil, errors.Wrap(err, "CreateOAuthToken Failed") - } - - return response.Data.CreateToken, nil -} - // CreateUser sends request to request to Houston in order to create a new platform User // Returns an AuthUser object containing an token func (c *Client) CreateUser(email string, password string) (*AuthUser, error) { diff --git a/houston/types.go b/houston/types.go index 3deb01b27..bee3fa12f 100644 --- a/houston/types.go +++ b/houston/types.go @@ -23,9 +23,10 @@ type HoustonResponse struct { // AuthConfig holds data related to oAuth and basic authentication type AuthConfig struct { - LocalEnabled bool `json:"localEnabled"` - GoogleEnabled bool `json:"googleEnabled"` - OauthUrl string `json:"googleOAuthUrl"` + LocalEnabled bool `json:"localEnabled"` + GoogleEnabled bool `json:"googleEnabled"` + GithubEnabled bool `json:"githubEnabled"` + Auth0Enabled bool `json:"auth0Enabled"` } type AuthUser struct {