The provided web push applicationServerKey is not valid - subscribe

I am trying to subscribe to web push via the function below.
function postSubscriptionBo() {
return navigator.serviceWorker.register('/service-worker.js')
.then(function(registration) {
const subscribeOptions = {
userVisibleOnly: true,
applicationServerKey: APPLICATION_SERVER_KEY
};
return registration.pushManager.subscribe(subscribeOptions);
})
.then(function(pushSubscription) {
console.log('Received PushSubscription: ', JSON.stringify(pushSubscription));
return pushSubscription;
});
}
These are the current steps:
1. Get the application server key from Firebase console > cloud messaging tab > server key
2. Encoded application server key with window.btoa(server key)
3. Removed tailing = from the server key
4. Browser throws exception: The provided web push applicationServerKey is not valid.
Suggestions on what I am doing wrong here?
Thanks.

In the cloud messaging tab instead of using the server key, after generating a Web Push certificates public key (at the bottom of the same cloud messaging tab) and adding it instead of the server key, it worked.

Related

"Invalid API Key provided" using the stripe extension in firebase cloud functions

having a problem that when I try to run my cloud function where my secret key is being perceived as invalid. I am 99.99% sure that it is the same as is in the Stripe dashboard and have copied and pasted 100 times so I think it is something else.
{success: false, error: Invalid API Key provided: sk_test_**********************************************************************************************************************************************************************************************************}
If anyone could help that would be fantastic.
Can you double check if there's any extra empty space characters being added to the API key that you specified in the cloud function? Or if you are reading the API key from a config file, try hardcode it directly to the code and see if it solves the problem.
Initial thoughts...
Ensure you have setup a restricted key with the specified security.
Could this be an issue with the secret manager, invalidating your key here and reconfiguring https://console.cloud.google.com/security/secret-manager?referrer=search&project={your-project-id} may fix the issue.
If you install a new instance, do you still have the same issue?
If you can run locally, does the key work ok in small nodejs project for example, depending on which extension you are using:
import Stripe from 'stripe';
// invoices extension: apiVersion: '2020-03-02',
// payments extension: apiVersion = '2020-08-27';
const stripe = new Stripe('sk_test_...', {
apiVersion: '2022-11-15',
});
const createCustomer = async () => {
const params: Stripe.CustomerCreateParams = {
description: 'test customer',
};
const customer: Stripe.Customer = await stripe.customers.create(params);
console.log(customer.id);
};
createCustomer();

How to solve the {code: UNAUTHENTICATED, details: null, message: UNAUTHENTICATED}) error using Google Cloud Functions?

I am currently facing the above mentioned error when using the cloud_functions dependency on my Flutter app. My function https call is as follows:
final HttpsCallable callable = CloudFunctions(region: "region name").getHttpsCallable(functionName: 'function-name')..timeout = const Duration(seconds:30);
And my function invocation within the code is as given below:
onPressed: () async {
try {
dynamic resp = await callable.call(<String, dynamic>{
'message':'hello!',
'url': urlController.text,
});
setState(() {
imgurl = resp.data['image'];
time = resp.data['timestamp'];
});
I have added the ID I am using for authentication to my function via the console IAM. Unfortunately, I still keep receiving the following error:
PlatformException(functionsError, Cloud function failed with exception., {code: UNAUTHENTICATED, details: null, message: UNAUTHENTICATED})
How can I resolve that?
Thanks for your help in advance.
If you have deployed your function in "private mode", I mean, allow only authenticated user, you have to add a valid identity_token in the header of your request.
You have an example here, mostly on end user because it's your use case. Don't use a service account key file because your flutter app is public and you will share your secret publicly.
You can also use Cloud Endpoint with Firebase authentication mode. I wrote an article for setting up an authentication with API key. Simply update the authentication mode and it will works.

using postman to access firebase REST API

I'm trying to use postman to do REST API calls to firebase. I've managed to read from firebase when my security rule is to permit all users including unauthorized ones.
but when I use this rule :
{"rules":{".read": "auth != null", ".write": "auth != null"}}
I get 'error' : 'permission denied' from postman.
I did the request token for google's web oauth2.0 client and got the authorization_code token back.
I tried to use token in the URL and in the header, tried it with GET & POST request and still get denied.
please help.
Thanks in advance
The answers above did not work for me.
What did work for me was going to
Project Settings (top left corner gear) -> Service Accounts (far right tab) -> Database Secrets (left menu) -> Scroll down, hover over the bulltets and click Show
Use this as the auth key, i.e. .../mycollection.json?auth=HERE
For me it worked like this:
https://your-database-url/users.json?auth=YOUR_AUTH_KEY
Where can you get this AUTH_KEY?
you get this key from your Project Settings -> Database -> Secret Key
Try something like this
https://your-database-url/users.json?auth=YOUR_AUTH_KEY
Respone is a JSON of your USERS node
I created a Postman pre-request script for helping create a Authentication: Bearer JWT. Should save a lot of copy pasting when testing APIs with Firebase Auth. https://gist.github.com/moneal/af2d988a770c3957df11e3360af62635
Copy of script at time of posting:
/**
* This script expects the global variables 'refresh_token' and 'firebase_api_key' to be set. 'firebase_api_key' can be found
* in the Firebase console under project settings then 'Web API Key'.
* 'refresh_token' as to be gathered from watching the network requests to https://securetoken.googleapis.com/v1/token from
* your Firebase app, look for the formdata values
*
* If all the data is found it makes a request to get a new token and sets a 'auth_jwt' environment variable and updates the
* global 'refresh_token'.
*
* Requests that need authentication should have a header with a key of 'Authentication' and value of '{{auth_jwt}}'
*
* Currently the nested assertions silently fail, I don't know why.
*/
pm.expect(pm.globals.has('refresh_token')).to.be.true;
pm.expect(pm.globals.has('firebase_api_key')).to.be.true;
var sdk = require('postman-collection'),
tokenRequest = new sdk.Request({
url: 'https://securetoken.googleapis.com/v1/token',
method: 'POST',
body: {
mode: 'urlencoded',
urlencoded: [{
type: 'text',
key: 'key',
value: pm.globals.get('firebase_api_key')
},
{
type: 'text',
key: 'grant_type',
value: 'refresh_token'
},
{
type: 'text',
key: 'refresh_token',
value: pm.globals.get('refresh_token')
},
]
}
});
pm.sendRequest(tokenRequest, function(err, response) {
pm.test('request for access token was ok', function() {
pm.expect(response).to.be.ok();
});
const json = response.json();
pm.expect(json).to.an('object');
pm.test('response json has needed properties', function() {
pm.expect(json).to.have.own.property('access_token');
pm.expect(json).to.have.own.property('token_type');
pm.expect(json).to.have.own.property('refresh_token');
const accessToken = json.access_token;
const tokenType = json.token_type;
const refreshToken = json.refresh_token;
pm.environment.set('auth_jwt', tokenType + ' ' + accessToken);
pm.globals.set('refresh_token', refreshToken);
});
});
Note: Adding this answer as all Options listed here is either deprecated or not working(mostly due to missing steps).
Best way to make it work with Postman is to use Google OAuth2 access tokens. The provided link described in full length but I have added quick steps.
Step 1: Download Service-Accounts.json
Step 2: Generate Access token in Java (provided link described support in other language for this)
make sure to include this dependency:
implementation 'com.google.api-client:google-api-client:1.25.0'
OR
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.25.0</version>
</dependency>
Run this code to generate token(Copied from google's javadocs)
// Load the service account key JSON file
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
GoogleCredential scoped = GoogleCredential
.fromStream(serviceAccount)
.createScoped(
Arrays.asList(
"https://www.googleapis.com/auth/firebase.database",
"https://www.googleapis.com/auth/userinfo.email"
)
);
// Use the Google credential to generate an access token
scoped.refreshToken();
String token = scoped.getAccessToken();
System.out.println(token);
Step 3: Use the token in Postman
It is very simple to fetch data via Postman:
Here is how I did it
1 Your DB URL
https://YOUR_PROJECT_URL.firebaseio.com/YOUR_STRUCTURE/CLASS.json
2 Add API key in header as auth
auth = Value of your API_KEY
example:
We can use Firebase with postman for rest APIs
How we use Firebase in postman?
Copy your Firebase database URL
Paste it into your postman URL
Add .json at the last like shown in the image
Then play with your firebase database and make REST API

StarterSTS as a backup authentication store

I have setup startersts as the ClaimsProviderTrust in ADFS 2.0. Configured the login form to be displayed by changing the ADFS 2.0 web.config entry. I am trying to customize the login process here such that when some one enter's email address he will be logging into StarterSts otherwise through Active Directory which is provided by the ADFS 2.0 Installation. I had tried the code in the post http://blogs.msdn.com/b/card/archive/2010/01/27/customizing-the-ad-fs-2-0-sign-in-web-pages.aspx
protected void SubmitButton_Click( object sender, EventArgs e )
{
try
{
SignInWithTokenFromOtherSTS( UsernameTextBox.Text, PasswordTextBox.Text );
}
catch ( Exception ex )
{
//
// Fall back to signing in locally with the given username and password.
//
SignIn( UsernameTextBox.Text, PasswordTextBox.Text );
}
}
I just don't know what is the values for variables OtherSTSAddress and YourSTSAddress. Is there any more configuration i need to do after making this address correct
As per the link you provided:
const string OtherSTSAddress = "https://ipsts.federatedidentity.net/SecurityTokenService/InteropSts.svc/Sts";
const string YourSTSAddress = "https://your-sts/adfs/ls/";
So the former is the WS-Trust endpoint of StarterSTS.
The latter is the ADFS WS-Fed endpoint. Just substitute the URL of the box where you installed ADFS in the "your-sts" section.
According to the article, that's all you need.

use UCMA 3.0 to create a SIP client

I am just wondering if UCMA 3.0 SDK supports this.
I plan to use the SIP client to place a call to a standalone UCMA application, which will use VXML to play a prompt. Thanks.
You need to provision an Application Endpoint first following General application activation steps.
Follow these steps using ucma 3.0 API after :
1) Create a new collaboration platform. Using
X509Certificate2 cert ="your certificate thumb here";
CollaborationPlatform _collabPlatform;
ServerPlatformSettings settings = new ServerPlatformSettings(Name, LocalhostFQDN, ServicePort, ServerGruu, cert);
_collabPlatform = new CollaborationPlatform(settings);
_collabPlatform.AllowedAuthenticationProtocol = SipAuthenticationProtocols.Ntlm;
_collabPlatform.BeginStartup(PlatformStartupCompleted, _collabPlatform);
2) Create a new Endpoint.
Here is the callback.
private void PlatformStartupCompleted(IAsyncResult result)
{
try
{
_collabPlatform.EndStartup(result);
ApplicationEndpointSettings settings = new ApplicationEndpointSettings( AgentUri, ServerFQDN, ServerPort);
// For registered endpoints (recommended).
settings.UseRegistration = true;
_localEndpoint = new ApplicationEndpoint(_collabPlatform, settings);
_localEndpoint.BeginEstablish(EndpointEstablishCompleted, null);
}
catch (ConnectionFailureException connFailEx)
{
// ConnectionFailureException will be thrown when the platform cannot connect.
}
catch (RealTimeException rte)
{
// Any other RealTimeException could occur due to other error.
}
}
}
private void EndpointEstablishCompleted(IAsyncResult result)
{
_localEndpoint.EndEstablish(result);
//Register Event for incoming call here.
}
If i get your question correct, you want to create standalone ucma application which can play prompt when someone call using sip phone. Right? If so it is possible. For the sip phone you can use Phoner lite or xlite. But phoner lite does not support for call transferring.
For create standalone application check this http://www.ksac.com/blog/bid/58799/UCMA-3-0-Programs-Without-Lync-Server