How to hookup a Cloud Function for Google Identity Platform's beforeSignIn event via Terraform? - google-api

I want to setup a cloud function via Terraform for beforeSignIn event in Google Identity Platform. Google cloud documentation explains how to do this manually as shown in this screenshot.
My question is, How to do this via Terraform?
I couldn't find anything in Google Identity configuration side (google_identity_platform_project_default_config). So I thought this should be configured from the Cloud Functions side, and I tried to use event_trigger when creating the function as follows via terraform:
resource "google_cloudfunctions_function" "function" {
// ...
event_trigger {
event_type = "providers/cloud.auth/eventTypes/user.beforeSignIn:password"
resource = projects/<my-project-id>
}
}
But I'm getting 400 Bad Request from Google when trying to terraform apply with the following message:
Unknown event_type providers/cloud.auth/eventTypes/user.beforeSignIn:password
This error makes sense because this event is not in the supported event types in cloud functions. You can get all the supported event types list from gcloud functions event-types list command (example output here).

Related

Cognito trigger wrong lambda event

I'm using UpdateUserAttributes (AWS JAVA SDK) to update the user email. However, I'm not using the default email sender from Cognito but I'm using the custom email sender which will trigger the Lambda function. I'm facing two issues:
Based on AWS documentation: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-email-sender.html
The trigger source value should be "CustomEmailSender_UpdateUserAttribute" but the value that I see in the cloud watch is always "CustomEmailSender_VerifyUserAttribute".
I added the key-value to the clientMetaData but on the lambda request payload, the clientMetaData is always null.
Does anyone have to face these issues? and how did you bypass it?

Azure Bot-Builder : dispatch refresh fails with 401 error

We provisioned bot services using "msbot clone services ..." command. As part of this command a *.dispatch file is created with all the correct details.
The dispatch aggregates QnAMaker knowledge base and a LUIS app. We have verified the .dispatch file and also the .bot file to ensure correct keys are being used. The only change if any is we are not using starter_key in LUIS, rather we have generated a new key and this new key reflects in .dispatch and .bot file (when decrypted).
We have encrypted the .bot file correctly and tried following commands, and both fail with same error:
dispatch refresh --bot mybot.bot --secret
dispatch refresh --dispatch dispatch-file.dispatch
Error
Exporting LUIS application...
ERROR
One or more errors occurred. (The remote server returned an error: (401) Access Denied.)
Request url: https://westus.api.cognitive.microsoft.com/luis/api/v2.0/apps/<LUIS-APP-ID>/versions/0.1/export
Response: { "statusCode": 401, "message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription." }
There are two different keys being used to use Dispatch CLI tool. Authoring key and subscription key. Authoring key is the key from luis.ai portal and needed to export the LUIS sources for Dispatch and to upload the newly created Dispatch app to luis portal. Subscription key is optional and is used for hitting luis endpoint/prediction API. If subscription key (created from Azure portal for LUIS Cognitive Service) is put in place of authoring key, Dispatch CLI won't be able to create and upload/refresh Dispatch app into luis. This is the expected behavior at the moment.
Having the exact same issue. With the starter key everything worked fine.
Edit: seems like an issue with Microsoft API.
You can use the starter key to update the dispatch model even though the query limit is reached.
My workaround was:
replace the subscriptionkey with the original starter key (authoringkey in luis)
run dispatch refresh
switch the keys again to allow for queries

Hot to enable Cloud Elements Microsoft Graph Calendar webhooks for all calendars?

By default, when I integrate my Microsoft account with cloud elements:
https://developers.cloud-elements.com/docs/elements/microsoftgraph/
I only get notifications for my default calendar. But, in fact, I have like 5+ calendars. I want to get notifications about changes in all of them.
For now, I can only think of making a new end-point that accepts calendar ID and then I invoke this endpoint with the result of invocation:
GET /calendars
But, this looks like a hack. Is there a better solution to listen to all the calendars that I have using Cloud Elements?
According to your description, I assume you want to get the notifications for your calendar when the calendar changed.
We can use the subscription endpoint to get the notifications. For more detail about this endpoint, we can refer to this document
In the Cloud Elements UI, if you select the instance and click the api docs you will see four sections "information", "setup", "resources", and "models". Select resources and you will see one that has POST /webhooks
This is the call the Cloud Elements sends on webhook provision. If you want to change the body of the webhook go to the PreRequest Hook where you will see javascript that is creating a post body that will be sent to Microsoft.
By default the body you see in the javascript looks like:
var body={
"changeType": "created,updated,deleted",
"notificationUrl": "{webhookCallbackUrl}",
"resource": "/me/events",
"expirationDateTime": newDate
}
If you want to change what resources you get notification for you can do so in this body and using the documentation that was provided in the previous answer

Luis: Access denied due to invalid subscription key

I am facing following issue when i try to update application on Luis using following request:
https://westus.api.cognitive.microsoft.com/luis/api/v2.0/apps/app-id-here
header:
Ocp-Apim-Subscription-Key:paid-subscription key
body:
{
"name": "Name of luis app",
"description": "string"
}
I am getting following error:
{
"statusCode": 401,
"message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription."
}
I am using paid subscription from Azure portal with westus region. Still facing this issue.
However, This key works when I try to get top scoring intent using following request:
https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/luis-app-id?subscription-key=subscription-key-azure&timezoneOffset=-360&q=hi
This is really weird as sunscription key works for GET request but not for PUT or POST request.
Any suggestions?
PS: I am using paid subscription key.
The (subscription) keys created with a Cognitive Service LUIS resource in Azure Portal, even when added to with Assign resource in luis.ai, can only be used for runtime queries on a defined app.
The authoring endpoints on LUIS Programmatic APIs v2.0 - to create and manage apps and their elements - can only be used with the Authoring Key available in the luis.ai portal.
More information can be found in Authoring and query prediction endpoint keys in LUIS
It looks like you have two issues you are working thru here.
First, the API you are trying to post to should read "https://[location].api.cognitive.microsoft.com/luis/api/v2.0/apps/{appId}/publish". From the looks of it, you are missing the 'publish' at the end of your API call.
Second, the paid subscription key needs to be added to your LUIS app. Can you confirm it has been added? If not, follow these steps to do so:
Click Manage => Keys and Endpoints.
Next, click 'Assign resource'.
A window will pop up allowing you to select the tenant, subscription, and the key to use.
Click OK.
Click 'Publish' to make the newly generated endpoint accessible.
Make sure you add subscription primary key value in my request and also make sure you have associated your API with the product which you used the Primary key

Can't cancel a stripe subscription through Parse API when user has more than one subscription

I am building site that allows users to signup for multiple subscriptions. The Parse.com / Stripe API we use allows me to create multiple subscriptions for each user. However, if a user has more than one subscription, and I attempt to cancel any of them, I get an error that the user has more than one subscription and that I must identify which subscription I am referring to. The problem is, that I do attempt to pass the subscription ID to into the API (see below) but it just seems to get ignored. Stripe clearly supports this second parameter in their API, but the Parse documentation does not show a second "subscriptionId" parameter.
The following Parse Cloud Code (which works perfectly as long as the user has only one subscription)
Parse.Cloud.define("cancelStripeSubscription", function(request, response) {
Stripe.Customers.cancelSubscription(request.params.customerId, request.params.subscriptionId, true, {
success: function(httpResponse) {
response.success("Cancellation Complete");
},
error: function(httpResponse) {
response.error("Error: " + httpResponse.message);
}
});
});
Here is the relevant Parse/Stripe Cloud Code API - https://parse.com/docs/js/api/symbols/Stripe.Customers.html#.cancelSubscription
Here is the equivalent Stripe API clearly showing a second "subscriptionId" parameter. https://stripe.com/docs/api/node#cancel_subscription
I'm hoping that the Parse/Stripe module does support multiple subscriptions.
Thanks for any help!
Unfortunately, Parse's Stripe API library is pretty old and was built against an old version of the API when only 1 subscription was possible. You'd either just have to do 1 subscription per customer or generate the web request to Stripe's API yourself not using the library.

Resources