import VAPID registrations into firebase asks for OAuth2 - firebase

I'm following the steps described in google doc: import_push_subscriptions and I'm getting the 401 error message when trying to import one VAPID registration via curl:
"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."
My request looks like this:
curl -X POST -H "Authorization:key=hidden-authorization-key"
-H "Content-Type:application/json"
-d #data.json https://iid.googleapis.com/v1/web/iid
And here is the data.json content
{"endpoint": "https://fcm.googleapis.com/fcm/send/hidden-endpoint-hash",
"keys": {
"auth": "hidden-auth",
"p256dh": "hidden-p256dh"}
}
Note: we used the same hidden-authorization-key when we were importing ios tokens via the batchImport endpoint described here: create_registration_tokens_for_apns_tokens which worked as expected but the webpush import asks for OAuth2 which is strange since we are sending the Authorization:key.

It seems that firebase team fixed it. I've just tried to send to firebase newly created VAPID registration and got the long token as a response.

Related

Google Analitics API error: Request is missing required authentication credential

I'm trying to get info from google analitics from api but always get this error:
I've made OAuth2 and got token, but I don't know where to put it.
Can someone explain what have I done wrong?
The issue you are having is that the call has not bee authorized. To access private user data you need permission which means you need to send a properly authorized access token along with your request
This is sent as an Authorization header, something like this.
curl -X POST -H "Authorization: bearer xxxxxxxxxxxxxx" "https://analyticsreporting.googleapis.com/v4/reports:batchGet"

Get 401 "Signature mismatch. Authorization signature or client credential is wrong." (JS)

When I call API to get token, this message shows up and I don't know why and how to fix it 1
And this is my Authorization: OAuth oauth_consumer_key="V3R6bm******DznqE-ellA", oauth_nonce="bbo8dYK6anE6JZsEIhj2RmKuEwV0****", oauth_signature="UQH1OnFWEscFbyZIx4DRn9qSOW+nvIlzCEgXrjm***=", oauth_signature_method="HMAC-SHA256", oauth_timestamp="1654152360", oauth_version="1.0"
Please refer to the below Steps to use OAuth 2.0 tokens and follow the instructions:
Step 1: Register your application
If you don't already have a HERE account, see Get a HERE account.
Sign in to developer.here.com.
Click your name, select Projects, and then your project from the list. Your project details and available application credentials are then displayed.
Select REST or HERE SDKs and click Generate App. When your application is created, its App ID is displayed.
Click Create Credentials to generate a maximum of two access keys for your application. The access key is created and displayed in a pop-up window. Download and securely store the access key secret. Also download the credentials.properties file as instructed.
Step 2: Get a token
For instructions on getting a token, see Code an OAuth 2.0 token request.
Step 3: Use the token
You have now successfully obtained an access bearer token to use in making REST requests to HERE APIs.
Include the token in the HTTP Authorization header of your REST requests as a bearer token:
Authorization: Bearer <token>
Sample REST Request
GET /maptile/2.1/maptile/newest/normal.day/13/4400/2686/256/png8
Host: 1.base.maps.ls.hereapi.com
Authorization: Bearer eyJhbGceOyJSAMPLEiIsImN0eSISAMPLEt7VTFIllwIM0cKNCjN2WCCTqlwEEmk-t3gx1BpqUFoeBSAMPLEvhj8nl-RBGcyoljY...
Cache-Control: no-cache
Note: If you are upgrading to API key and currently have old app code credentials, you can remove them by clicking Remove APP CODE credentials and use your new API key credentials in their place.
For more details refer to the following documentation link: https://developer.here.com/documentation/identity-access-management/dev_guide/topics/dev-token.html

FCM Push - Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential

I am trying to send fcm message to specific topic by using cURL command but it says error like
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
I used server key from firebase console
I followed this FCM Documentation
How to resolve this 401 error.
Actually I think why, this is because you need a Service account that will handle it for you.
So follow the steps here and this will make you generate a new key pair. With this key, you can get the access token from a code (see in python below but the documentation has support for NodeJS / Java) :
def _get_access_token():
"""Retrieve a valid access token that can be used to authorize requests.
:return: Access token.
"""
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'service-account.json', SCOPES)
access_token_info = credentials.get_access_token()
return access_token_info.access_tokenmessaging.py
And you just have to print this value, copy-paste it and use it as the Bearer OAuth 2 access token.

Firebase bearer token from OAuth2 playground

I'm trying to test my application that uses Firebase for push notifications using postman.
I'm specifically testing the Http v1 Api, and looking how to authorize the request.
What I need to get right is getting the OAuth2 token to use in Postman, which I should be able to do on the OAuth 2.0 playground although I'm not sure how.
I have my privatkey.json file that I've downloaded from the firebase console, I just need to know how to use it to get the token that I would add as a bearer authorization header for my POST requests
I was able to send a message through the FCM v1 HTTP API by requesting the following scopes in the OAuth2 playground:
email, https://www.googleapis.com/auth/firebase.messaging
After authorizing this, I exchanged the authorization code for refresh and access tokens.
I then passed the resulting access token into the call with FCM:
curl -X POST -H "Authorization: Bearer MY_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{"message":{
"notification": {
"title": "FCM Message",
"body": "This is an FCM Message",
},
"token": "MY_DEVICE_TOKEN"
}
}' https://fcm.googleapis.com/v1/projects/MY_PROJECT_ID/messages:send
In the above CURL request replace the following placeholders with the relevant values for you:
MY_PROJECT_ID is the Firebase project ID, which you can get from the project settings page in the Firebase console
MY_DEVICE_TOKEN is the registration token of the device that you want to send the message to. For a web client, see how to get the current registration token.
MY_ACCESS_TOKEN is the OAuth2 access token that you got from the OAuth2 playground using the steps outlined above.
The FCM documentation on authenticating FCM v1 requests may be confusing since it only calls out the OAuth2 token. It actually first generates a self-signed JWT (JSON Web Token) by calling new google.auth.JWT(...). This involves downloading a private key, and generating the JWT locally through a JWT library.
The self-signed JWT is then passed to jwtClient.authorize(...), which gives back tokens including an access_token. The latter is an OAuth2 access token, similar to the one we got above.
I created a small project on hithub that includes both a postman collection and environment and nodejs project that uses the downloaded service-key.json to generate an access token which solves my problem above. It's not as elagent as using only postman (which to me seems impossible), but it works well enough since the access tokens live for about an hour.

Drupal8 Oaut2 add a grant type "password" to client

I work on Drupal8 project and created Rest API, everything works fine until I want to add Oauth2 when I try to get a token I got an invalid grant type error.
This is the error code:
{
"error": "invalid_grant",
"message": "The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.",
"hint": "Check the configuration to see if the grant is enabled."
}
This is the url that i called:
http://myserver/oauth/token?grant_type=password&client_id=6db9da8d-b831-4381-b279-381bc5a57e90&scope&username=webmasterrest&password=webmasterrest&client_secret=$S$EamACyfemGWic74kmkwUvphMmr9FL132KC297mI1GEkTKhyBJyAo
I added a client, but I can't add a grant type "password" to this client, any help please?
To add Oauth 2 authentification
Install the module using Composer: composer config repositories.drupal composer https://packages.drupal.org/8 && composer require drupal/simple_oauth:^2. You can use any other installation method, as long as you install the OAuth2 Server composer package.
Generate a pair of keys to encrypt the tokens. And store them outside of your document root for security reasons.
openssl genrsa -out private.key 2048
openssl rsa -in private.key -pubout > public.key
Save the path to your keys in: /admin/config/people/simple_oauth.
Go to REST UI and enable the oauth2 authentication in your resource.
Create a Client Application by going to: /admin/config/services/consumer/add.
Create a token with your credentials by making a POST request to /oauth/token. See the documentation about what fields your request should contain
(Not shown) Permissions are set to only allow to view nodes via REST with the authenticated user.
Request a node via REST without authentication and watch it fail.
Request a node via REST with the header Authorization: Bearer {YOUR_TOKEN} and watch it succeed.
From this
NOTE: I user drupal/simple_oauth version 2.x because i got an exception n version 3.x

Resources