Freeagent authentication with accesstoken - api

I go through with https://dev.freeagent.com/docs/oauth for implement the API.
But not able to get the access-token. I got the code but the process to get access-token I face below issue.
Request:
POST /v2/token_endpoint HTTP/1.1
Host: api.sandbox.freeagent.com
grant_type: authorization_code
code: 4/z7IBgRS-Pjx6y5-djE-uaRAjqeYleIdVCyjwiFgnfdg
redirect_uri: https://google.com
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
client_id: 3go0PEltpEHFFzEOdliIzQ
client_secret: OLefVbuT3LhEqpMh-2iq3w
Cache-Control: no-cache
Postman-Token: d47f46b7-9e1d-2969-8a40-53ee2120d5c2
Response:
{
"error": "invalid_request"
}

FreeAgent Quick Start Guide
It's very condensed and not entirely clear but I followed along with the FreeAgent Quick Start Guide and eventually was able to get the Access Token as well as the Refresh Token.
Using the Google OAuth 2.0 Playground I was able to authenticate myself and receive the various responses.
It's all in their guide.
Good luck!

Related

Xero - Getting 401 Unauthorized for get:/Accounts, scopes added

I am trying to get a list of my accounts using
GET:https://api.xero.com/api.xro/2.0/Accounts with my access token.
The response is 401 / Unauthorized
My app has these scopes:
accounting.transactions
accounting.transactions.read
accounting.settings
accounting.settings.read
accounting.contacts
accounting.contacts.read
accounting.settings.read should be adequate according to the Scopes documentation
I am using the same PHP code used to GET:/Invoices which works fine, with headers:
Accept: application/json
authorization: Bearer $access_token
I am using a Custom Connection, as we have a machine-to-machine setup with no interface.
The App configuration screen, and available scopes are shown here:

Authorizing API Requests to 3rd Party Services in Mongodb Realm

I'm building a React app that allows users to login with Google and then connects to a webhook/3rd Party service in Realm. The service should only return data that the users own.
I've set up the OAuth 2 with Google and can get back access_token for a user and I then pass it in the header (I've also tried the URL params) to the webhook. But I get an error back saying:
400 "no authentication methods were specified" - "Invalid Parameter".
After much testing, I've identified that it must be a Realm issue - but I can't figure out what.
I've tried authenticating with Google in Postman and sending a request from there like this:
GET <incoming_webhook URL>
Request Headers
Authorization: Bearer <access_token>
User-Agent: PostmanRuntime/7.26.10
Accept: */*
Host: us-east-1.aws.webhooks.mongodb-realm.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
But I get the same error.
In Realm I have "Google" enabled as an authentication providers (and the authentication works just not the authorization through the webhook).
Per https://docs.mongodb.com/realm/services/configure/service-webhooks/#configure-user-authentication, you can choose email/password, an API key, or a custom JWT token. I don't know whether you can use google login directly to a webhook, but you're probably better off making a realm function instead.
Regarding the error no authentication methods were specified, you can specify the type of authentication method (using a custom JWT as an example) by either:
putting it in the header:
Header: jwtTokenString, Value: eyJhbGci.....
OR
by including it as part of the webhook body:
{
"jwtTokenString":"eyJhbGci...",
"mydata": "my data value"
}
If you try to use both methods, you get a multiple authentication methods used error. HTTP Bearer tokens in the header, etc, are useless here.
For an API Key, instead of jwtTokenString, use api-key; or email`password` for email\password authentication.
I found these methods of providing authenticating information really unintuitive and the documentation very unclear.

Google Cloud Storage auth token in React Native

With Google Could Storage my core problem is AUTH_TOKEN in required Authorization header.
POST https://www.googleapis.com/upload/storage/v1/b/myBucket/o?uploadType=media&name=myObject HTTP/1.1
Content-Type: image/jpeg
Content-Length: [NUMBER_OF_BYTES_IN_FILE]
Authorization: Bearer [YOUR_AUTH_TOKEN]
[JPEG_DATA]
Here it's explained how to obtain the auth token (OAuth 2.0 for Service Accounts).
POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.com
Content-Type: application/x-www-form-urlencoded
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvcHJlZGljdGlvbiIsImF1ZCI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbS9vL29hdXRoMi90b2tlbiIsImV4cCI6MTMyODU3MzM4MSwiaWF0IjoxMzI4NTY5NzgxfQ.ixOUGehweEVX_UKXv5BbbwVEdcz6AYS-6uQV6fGorGKrHf3LIJnyREw9evE-gs2bmMaQI5_UbabvI4k-mQE4kBqtmSpTzxYBL1TCd7Kv5nTZoUC1CmwmWCFqT9RE6D7XSgPUh_jF1qskLa2w0rxMSjwruNKbysgRNctZPln7cqQ
The request (above) requires the assertion param, which is JWT generated using RS256 (below).
{"alg":"RS256","typ":"JWT"}.
{
"iss":"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5#developer.gserviceaccount.com",
"scope":"https://www.googleapis.com/auth/prediction",
"aud":"https://www.googleapis.com/oauth2/v4/token",
"exp":1328554385,
"iat":1328550785
}.
[signature bytes]
I have problem generating JWT in React Native using react-native-jwt.
Has anyone got around the authorization for Google Could Storage, while using React Native?

Youtrack REST API "Failed to create service account from Hub, giving up" error

I'm trying to receive data from REST Api after Authorization in Hub. Here is my actions:
1.Authenticate application in Hub using Client credentials flow (by the way, is it right flow choice for chat bot?)
POST /api/rest/oauth2/token HTTP/1.1
Host: hub.example.com
Authorization: Basic base64(service_id + “:” + service_secret)
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&scope=YOUTRACK_SERVICE_ID
2.Then i'm trying to get issues from YouTrack, using recieved access token
GET /rest/issue HTTP/1.1
Host: yt.example.com
Authorization: Bearer ACCESS_TOKEN
Accept: application/json
Response has status 500 with this message
{"value": "Failed to create service account from Hub, giving up"}
Both Hub and YouTrack is stand-alone.
What's going on and what should i do? Thanks
Updating YouTrack to fresh build fixes issue.
Thanks to Jk1's comment above.

Parse tweets Twitter API

I am trying to get the latest tweets from a twitter user. This is what I've got so far:
$string = file_get_contents("https://api.twitter.com/1/statuses/show.json?id=Cristiano&include_entities=true");
$json_=json_decode($string,true);
This is my error message:
{"errors":[{"message":"Bad Authentication data","code":215}]}
What is the problem?
You'll want/need to migrate to the latest version of the API: 1.1. More information about the deprecation of version 1 can be found at the Twitter API Calendar of Changes documentation.
Next, you'll need to authenticate to the API prior before having access to it. More information about that can be found at the Twitter API Authentication & Authorization page.
POST /oauth2/token HTTP/1.1
Host: api.twitter.com
User-Agent: My Twitter App v1.0.23
Authorization: Basic eHZ6MWV2RlM0d0VFUFRHRUZQSEJvZzpMOHFxOVBaeVJn
NmllS0dFS2hab2xHQzB2SldMdzhpRUo4OERSZHlPZw==
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Content-Length: 29
Accept-Encoding: gzip
grant_type=client_credentials
That is the required HTTP POST request. How do I sent it using PHP?