OAuth lib for Chrome Extensions and Salesforce API - google-chrome

I'm try to authorize to Salesforce APIs using the Chrome Extension OAuth Library, but I get the following response from Salesforce when I send a signed request using oauth.sendSignedRequest() method:
<response><error>LOGIN_OAUTH_INVALID_DSIG</error><message>Failed: Signature Invalid</message></response>
Any thoughts on what could be causing this?

Can you post your oauth object here.
I bet you are using 'consumer_key': 'anonymous',
'consumer_secret': 'anonymous',. You need to check weather Salesforce accepts consumer key and secret as anonymous or not.

I ended up creating my OAuth 2.0 Library for Chrome Extension that works fine with Salesforce. Ping me if you would like to get a copy of the library.

Related

Why can't I get Google API Devices to work

I am trying to get started with using Google API specifically in regards to obtaining a listing of Chrome devices in our organization. We have a current list of Chrome Devices in Google Admin. When I go to "API Explorer" here:
https://cloud.google.com/identity/docs/reference/rest/v1/devices/list
And enter the request parameters I can't get it to work.
First of all I do not know how to obtain an access token other than using the "OAUTH 2.0 Playground". That link is
https://developers.google.com/oauthplayground/
I have tried that but apparently I need to somehow enable one of the following OAuth scopes:
https://www.googleapis.com/auth/cloud-identity.devices.readonly
https://www.googleapis.com/auth/cloud-identity.devices
https://www.googleapis.com/auth/cloud-identity
Which I don't seem to be able to find in the OAuth playground.
In any case, I did obtain a token through the OAUTH 2.0 Playground to use in the "API Explorer". I am pretty sure I didn't use the correct OAuth scope either. In any case, maybe I can try using an API Device List in OAUTH 2.0 Playground but haven't figured it out yet.
Seems to be easier to find and use in "API Explorer". But when I use the Auth Token in API Explorer, devices.list in
GET https://cloudidentity.googleapis.com/v1/devices,
which I acquired through OAUTH 2.0 Playground, I get the error:
"Request had insufficient authentication scopes"
I get the same error in OAUTH 2.0 Playground if I try to use that same API request in OAUTH 2.0 Playground. But simply cannot find the following OAuth scopes, which the API explorer says is required for this particular API request of
"GET https://cloudidentity.googleapis.com/v1/devices"
I am just looking to try this out (obtaining a list of chrome devices through the Google Cloud API), which I know our organization has in our admin console.
I have not activated a Google Cloud Trial yet, so maybe that is the problem. I don't really know if the API Explorer or OAUTH 2.0 Playground requires that.
Maybe there is a different API request to accomplish what I am looking to do.
Maybe there is a different way to obtain an access token. I have gone in the google cloud console,
https://console.cloud.google.com
created a project, and created an API Key, and an OAUTH 2.0 client.
Any help would be appreciated.
Thank you.

404 error when deploying a Google Apps script via the REST API

I'm trying to deploy a Google Apps script via the Google REST API, and I'm using the API Explorer to perform that.
This is the method I am testing:
https://developers.google.com/apps-script/api/reference/rest/v1/projects.deployments/create
Executing the method via the API Explorer returns a 404 error. I have verified that the scriptId in question does exist, and have tried several other scriptIds, to no avail. I have also made sure the permission scopes are properly set.
This is what the API Explorer gives me.
Worth mentioning that the same scriptId works when calling another method such as projects.get.
Is there anything I am missing, or is this an issue on Google's end?
In case of the latter, what are the steps to contact Google Apps Script's team and inform them of this issue?
Your versionNumber is incorrect. The Requested entity here refers to the version of your script. You need to go to File>Manage Versions>Save New version to create a new version(or create one with the api1) and use that version number in the request body.
Check your authorization scopes. You need to have the following scope enabled:
https://www.googleapis.com/auth/script.deployments
If its not in the list of available scopes in API Explorer then you'll need to add it manually (there is an area at the bottom of the authorization dialog where you can add scopes).
Google's API Explorer uses API keys to authorize requests. In some cases an API key is not sufficient and an OAuth2 (bearer) access token is required. As an alternative you can create an Apps Script project and add the appropriate scopes via the manifest file(appsscript.json). Then you can use UrlFetchApp.fetch() to test the API directly.

Access Google Drive REST without google sdk

I have a lightweight node.js module that needs to pull from google drive. They have a REST/HTTPS interface but AFAICT it's only accessible via their SDK. I want to use REST/HTTPS so I don't have to use an SDK. Is this possible for file download? For file find (file:list e.g. https://developers.google.com/drive/v3/reference/files/list)?
I don't understand why you think it's only accessible using an SDK. The link you posted clearly shows the URL endpoint, lists the optional parameters and gives the format of the JSON response.
If you click "Try it now" and open your browser console, you will see the http request and response which you can mirror in your app.
The only thing you also need to consider is that before making a REST request to Google, you must obtain an Access Token and set it in an Authorization: Bearer xxxxxxxx header, or provide it as a query parameter as &access_token=xxxxxxxxx

How to authenticate a twitter api request?

I am trying to make twitter api requests in my browser (I wan to look at the JSON before writing code to parse it in my android app) but every request is returning:
{"errors":[{"message":"Bad Authentication data","code":215}]}
So how do I properly authenticate the request?
I've been using OAuth.io for a while to do proper authenticated requests: they specifically have a feature called Request API or something like that: check their Documentation this might help you I hope.

Chrome Identity API - POST request

I am trying to develop a chrome extension in which I need to use 3rd party Oauth2 authentication. The third party service I want to use, only supports POST requests. But it seems that the launchWebAuthFlow method in the Chrome Identity API, only supports sending GET requests, as all the query parameters are sent in the URL itself. Is this correct? If yes, how should I do authentication?
UPDATE : The API I want to connect is that of Pocket
Partially you're right about POST requirements. But it is only used to initialize Oauth flow.
According to the documentation:
1) You must make a POST request to obtain a request token from Pocket auth service
2) Redirect user to the auth page: https://getpocket.com/auth/authorize?request_token=YOUR_REQUEST_TOKEN&redirect_uri=YOUR_REDIRECT_URI
Which means that you have to make a simple XHR to retrieve request token and then you can use chrome.identity.launchWebAuthFlow function to begin Oauth flow.
Did you try launchWebAuthFlow? You may find that it works. Once authenticated, you can exercise the API via POST, using XMLHttpRequest. (launchWebAuthFlow only handles the authentication, not the API itself.)