How to get valid/invalid login from OAuth 2 for Ruby

68 Views Asked by At

I'm running the Restforce API, which I believe uses OAuth 2 from what I have read. The login I have works, but at this point I am just trying to make something that returns whether the login was successful or not. I have the username, password, security token, client id, and client secret.

When I print the result it returns:

#Restforce::Data::Client:0x0055b1b3433798

Is there a way I can have it return "success!" or "failure!" or anything like that?

URI_SF = URI.parse(URI.encode("https://na35.salesforce.com"))

def use_restforce_api()
    rf_client = Restforce.new(username: EMAIL,
                       password: PASSWORD,
                       security_token: SECURITY_TOKEN,
                       instance_url: URI_SF,
                       client_id: CLIENT_ID,
                       client_secret: CLIENT_SECRET,
                       api_version: '38.0')

end
1

There are 1 best solutions below

0
Mike On BEST ANSWER

Well I figured it out by going through the documentation. It was:

info = rf_client.get(response.id).body
puts info

On success it returns information where I can access every bit with info.username, info.object.

On failure of client_id and client_secret, they each give their own respective messages. On failure of the username, security token, or API key, it gives the same failure message.

I can work with that.