0

I am trying to use the Cloud Foundry go-cfclient to work with IBM Bluemix and the REST API in Go. I already fail with the login process. I am using the following sample code and invoke the program by passing in the Bluemix endpoint "https://api.ng.bluemix.net" and my userid/password info.

package main

import (
    "flag"
    "fmt"
    "os"

    cfclient "github.com/cloudfoundry-community/go-cfclient"
)

func main() {
    api := flag.String("api", "", "API endpoint")
    username := flag.String("username", "", "User name")
    password := flag.String("password", "", "password")
    help := flag.Bool("help", false, "help")

    flag.Parse()

    if *help || len(*api) == 0 || len(*username) == 0 || len(*password) == 0 {
        flag.Usage()
        os.Exit(1)
    }

    config := &cfclient.Config{
        ApiAddress: *api,
        Username:   *username,
        Password:   *password}

    fmt.Println("user %v\n",*username)
    var (
        client *cfclient.Client
        err    error
    )

    if client, err = cfclient.NewClient(config); err != nil {
        panic(err)
    }
    fmt.Println(client)

    apps, err := client.ListApps()

    if err != nil {
        panic(err)
    }

    fmt.Println(apps)
}

The error returned is:

panic: Error getting token: oauth2: cannot fetch token: 401 Unauthorized Response: {"error":"unauthorized","error_description":"Bad credentials"}

What information needs to be provided? How can I log into Bluemix using the REST API?

2
  • I'm not familiar with the go library, but it looks like it accepts a Password attribute. Maybe that should be used instead of Token? Commented Feb 7, 2017 at 21:10
  • Sorry, it is Password, not the token. I had experimented with both to see whether the oauth token could be passed in. I corrected the code above. Commented Feb 8, 2017 at 6:29

1 Answer 1

1

Here is an example of logging into Bluemix using the REST API (in JavaScript).

You make a call to the login endpoint and request a token with your username and password from Bluemix.

body of request

headers of request

Sign up to request clarification or add additional context in comments.

3 Comments

Assuming that the example works, it will help to understand the flow. I am also looking into trace. However, the real problem would be how to use the go-cfclient library.
Well, from looking at this library, it looks like it's trying to get the token from https://uaa.ng.bluemix.net/oauth/token rather than https://login.ng.bluemix.net/UAALoginServerWAR/oauth/token which is the reason why it's failing authentication.
Yup. That's what I also found out so far. See here github.com/cloudfoundry-community/go-cfclient/issues/32 The question is now why it is using that URI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.