github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/authentication/auth.go (about) 1 package authentication 2 3 import ( 4 "errors" 5 6 bluemix "github.com/IBM-Cloud/bluemix-go" 7 "github.com/IBM-Cloud/bluemix-go/client" 8 ) 9 10 const ( 11 //ErrCodeInvalidToken ... 12 ErrCodeInvalidToken = "InvalidToken" 13 ) 14 15 //PopulateTokens populate the relevant tokens in the bluemix Config using the token provider 16 func PopulateTokens(tokenProvider client.TokenProvider, c *bluemix.Config) error { 17 if c.IBMID != "" && c.IBMIDPassword != "" { 18 err := tokenProvider.AuthenticatePassword(c.IBMID, c.IBMIDPassword) 19 return err 20 } 21 if c.BluemixAPIKey != "" { 22 err := tokenProvider.AuthenticateAPIKey(c.BluemixAPIKey) 23 return err 24 } 25 return errors.New("Insufficient credentials, need IBMID/IBMIDPassword or IBM Cloud API Key or IAM/IAM refresh tokens") 26 }