I am working on web app which will consume apis generated from composer rest server. Is there any document regarding the api endpoints of composer rest server, so that I can code my http get and post calls. I mainly want it to complete my multi user story at UI end.
Have you seen the swagger.json endpoint?
I think it will give you the information that you are looking for.
http://localhost:3000/explorer/swagger.json
Extra Information
When run in Multi-user mode the /wallet endpoints should also appear in the swagger.json (just tested using OAuth2.0 tutorial). Short extract follows:
{
"swagger":"2.0",
"info":{
"version":"1.0.0",
"title":"LoopBack Application"
},
"basePath":"/api",
"paths":{
"/wallet":{
"get":{
"tags":[
"Wallet"
],
"summary":"Get all of the business network cards in the wallet",
"operationId":"Card.getAllCards",
"parameters":[
...
...
Related
We have an authenticated HTTP cloud function (CF). The endpoint for this CF is public but because it is authenticated, it requires a valid identity token (id_token) to be added to the Authorization header.
We have another Node JS application that is deployed in the same Google Cloud. What we want is to call the CF from the Node application, for which we will be needing a valid id token.
The GCP documentation for authentication is too generic and does not have anything for such kind of scenario.
So what is the best way to achieve this?
Note
Like every google Kubernetes deployment, the node application has a service account attached to it which already has cloud function invoker access.
Follow Up
Before posting the question here I had already followed the same approach as #guillaume mentioned in his answer.
In my current code, I am hitting the metadata server from the Node JS application to get an id_token, and then I am sending the id_token in a header Authorization: 'Bearer [id_token]' to the CF HTTP request.
However, I am getting a 403 forbidden when I do that. I am not sure why??
I can verify the id_token fetched from the metadata server with the following endpoint.
https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=[id_token]
It's a valid one.
And it has the following fields.
Decoding the id_token in https://jwt.io/ shows the same field in the payload.
{
"issued_to": "XXX",
"audience": "[CLOUD_FUNTION_URL]",
"user_id": "XXX",
"expires_in": 3570,
"issuer": "https://accounts.google.com",
"issued_at": 1610010647
}
There is no service account email field!
You have what you need in the documentation but I agree, it's not clear. It's named function-to-function authentication.
In fact, because the metadata server is deployed on each computes element on Google Cloud, you can reuse this solution everywhere (or almost everywhere! You can't generate an id_token on Cloud Build, I wrote an article and a workaround on this)
This article provides also a great workaround for local testing (because you don't have metadata server on your computer!)
the sample here is not working and missing the azure function, any remarks on that: https://github.com/azure-ad-b2c/samples/tree/master/policies/selectemail
You need to build the REST API yourself.
The interface of the REST API is in the readme.
The REST API needs to respond with a JSON Array:
{
"emails": [
"email1#contoso.com",
"email2#contoso.com",
"email3#notrealemail.com"
]
}
To augment the sample, you would add an inputClaim to the Get-Emails technical profile to send an identifier in JSON to your REST API. Then your REST API can respond with an appropriate response in the format above.
I have deployed a chatbot with LUIS and QnA Maker. It works perfectly locally when I run it on Emulator. It loads up the adaptive cards at start of the chat and I get correct replies from LUIS.
However when I deploy the bot on Azure and test it on Web chat it gives the following error:
There was an error sending this message to your bot: HTTP status code InternalServerError
This is how my web.config looks like:
<configuration>
<appSettings>
<!-- update these with your BotId, Microsoft App Id and your Microsoft App Password-->
<add key="BotId" value="BotLuis" />
<add key="MicrosoftAppId" value="9f9564ef-d627-450f-b943-98b7338c0f31" />
<add key="MicrosoftAppPassword" value="myapp-password" />
</appSettings>
I get the values for AppID and AppPassword from the Applications setting of the web bot I created on Azure. I know they are correct since I used these values to setup locally using Emulator.
I deploy the code from github to Azure. My bot loads up just fine (The adaptive cards show) on azure web chat but after that any input I give to it, whether it is interactive card or chat command, I get the above error.
The application Insight shows the following exception:
POST to BotLuis failed: POST to the bot's endpoint failed with HTTP status 500
Problem Id:System.Exception at Microsoft.Bot.ChannelConnector.BotAPI+d__31.MoveNext
The developers tool console shows this when I interact with the bot:
https://webchat.botframework.com/v3/directline/conversations/3NgflndFbpzCRDtnMdZpjf-g/activities 502 (Bad Gateway)
if you paste the above link in a browser this is what you will get:
{
"error": {
"code": "BadArgument",
"message": "Missing token or secret"
}
}
I am lost at this point. I can understand the problem but I don't know how to go forward. Am I supposed to add the messaging endpoint of my bot in my code somewhere?
A link to github repo of the code:here
Bot State Service retired on March 31st, 2018.
Therefore your sample is missing state storage when you run it on Azure, while it will work locally.
To make your sample work, simply add the following lines to your Global.asax.csfile.
protected void Application_Start()
{
RegisterBotDependencies();
GlobalConfiguration.Configure(WebApiConfig.Register);
var store = new InMemoryDataStore();
Conversation.UpdateContainer(
builder =>
{
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
builder.Register(c => new CachingBotDataStore(store,
CachingBotDataStoreConsistencyPolicy
.ETagBasedConsistency))
.As<IBotDataStore<BotData>>()
.AsSelf()
.InstancePerLifetimeScope();
});
}
Please note that this sample uses InMemory storage and is therefore not intended for production use. Following the blog post, you can easily switch over to Azure Table storage or CosmosDB.
I've cloned your repository, added these lines of code and deployed it to a new bot instance on Azure. Webchat test was successful.
Summary
Taken from above blog post.
We’ve been encouraging bot developers using the Bot Framework to use their own custom state service for a while. The default Bot Framework State service was intended for prototyping purposes only, and not designed to accommodate production bots. The state service will be deprecated on March 31, 2018 and will no longer be supported. Bot developers moving forward will be able to prototype their bots using temporary local memory storage as described in this article. Creating your own custom state service for your bot provides multiple benefits including improved latency and direct control over your bot’s conversation state and contextual user conversation state information, and we’ve provided multiple resources to guide you to do so. We appreciate the feedback we’ve been receiving from the bot developer community, which has helped us a lot in improving the Bot Framework as a whole. We also hope that we can continue helping you – the bot developer community, create better and better bot experiences for your users.
Introduction
I have a hyperledger env running in secure mode by following this link https://hyperledger.github.io/composer/integrating/enabling-rest-authentication.html
and it works fine if I authenticate as specified in the document (hitting http://mydomain:3000/auth/github directly from the browser) and then access the Rest API from the http://mydomain:3000/explorer and could authorize as various participants (i.e, issuing identity and adding them to the wallet and setting one as default at a time) and could see the assets as per the .acl file.
Issue
But I started facing problems when I started integrating the Rest API's from my web application rather directly from the browser. As a first step from my web app, I called the http://mydomain:3000/auth/github to authenticate and then started calling the other APIs (transaction/list, etc.) but I do always get
Error 401: 'Authorization Required'
What i have tried
Gave my web application URL as the 'Redirect URL' in the env variable for the hyperledger. And upon successful authentication (calling http://mydomain:3000/auth/github) it successfully redirected to my webapp home page but afterwards accessing the Rest API's (from web app) again throws 'Authorization Required' error.
Environment variaable as below:
export COMPOSER_PROVIDERS='{
"github": {
"provider": "github",
"module": "passport-github",
"clientID": "CLIENT_ID",
"clientSecret": "CLIENT_SECRET",
"authPath": "/auth/github",
"callbackURL": "/auth/github/callback",
"successRedirect": "http://localhost:8080/home.html",
"failureRedirect": "/"
}
}'
Incorporated passport-github2 mechanism in my web application (i.e, registered my app with the oauth of github) and upon successful login to my web application; called the http://mydomain:3000/auth/github to authenticate to the blockchain and it did not work out as well.
I have a few questions:
Is it feasible to call the secured hyperledger Rest API's from another web application?
If Yes, how to do it? I don't find that information in the hyperledger composer documentation.
Have been trying this for a week now and have no answers. Any help would be greatly appreciated. Please let me know if anything is unclear. Thanks.
I commented about this problem on one of the existing hyperledger github issues(below link) & I want to share the solution that solved this problem for me.
https://github.com/hyperledger/composer/issues/142
Solution: as mentioned by user sstone1
Since the REST server is on a different port number to your web application, you need to specify an additional option to your HTTP client to pass the cookies to the REST server. Using the Angular HTTP client, you add the withCredentials flag, for example:
via Angular:
this.http.get('http://mydomain:3000/api/MyAsset', { withCredentials: true })
via JQuery AJAX:
$.ajax({
url: 'http://mydomain:3000/api/MyAsset',
xhrFields: {
withCredentials: true
},
headers: {
...
}
})
I am using Azure Functions to build some integrations between various systems. I new requirement is to respond to record updates in Salesforce. Some quick research yielded what seems like a good solution from the Salesforce side. Use Outbound messaging which can send SOAP requests on record modifications.
How to create Salesforce application that will send record to external web service when record created/changed(https://salesforce.stackexchange.com/questions/73425/how-to-create-salesforce-application-that-will-send-record-to-external-web-servi)
The challenge now is to be able create a SOAP listener in Azure Function. I have created basic HTTP Triggers for my other listeners. Is there anything "built-in" to Azure Functions that would allow me to easily consume the incoming SOAP request?
Salesforce has the basics for a solution based on a more traditional web service and an ASMX file but I am not sure if or how that can be applied in Azure Functions. (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_om_outboundmessaging_listener.htm)
That notification is just a SOAP request that is made over HTTP, so really not too different than a regular HTTP trigger request.
Although you could just treat that as a plain request and parse the contents yourself, Azure Functions does expose the great WebHook support we get from ASP.NET WebHooks, and luckily, there is a Salesforce receiver that significantly simplifies this task.
DISCLAIMER: It's worth noting that although the receiver is technically enabled in Azure Functions, there's no official support for it yet, so you won't find a lot of documentation and help will be limited to what you get on SO and Forums. Official support to this and other receivers will hopefully be coming soon, which means documentation, templates and UI support will become available.
To get started, you need the following:
Create a new function, selecting the GenericWebHook - CSharp template (this works for node as well, but I'll focus on C# here.
Follow the steps outlined on the ASP.NET WebHooks integration with Salesforce post in order to create the outbound message. Here you want to use the Function Url given to you by the portal WITHOUT THE CODE QUERY STRING (having the code there wouldn't hurt, but the receiver does not use that information).
IMPORTANT: Get your Salesforce Organization ID, which will be used for authentication and is located under Administer > Company Profile > Company Information > Salesforce.com Organization ID and back in the Azure Functions portal, open the Keys panel, delete your default function key (not host key) and create a new key, named default (this name is important) using the Organization ID value you got from Salesforce.
Go to Integrate
On the integration page, select Advanced Editor on the upper right (as mentioned, there's no official support, so the UI does not expose this. We're putting our explorer hats on and venturing into a more advanced workflow here :) )
Change the webHookType property value to sfsoap and save the configuration. Your function.json config should look like the following:
function.json:
{
"bindings": [
{
"type": "httpTrigger",
"direction": "in",
"webHookType": "sfsoap",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"disabled": false
}
Switch to the Develop tab. We're ready to write our code.
This is where the ASP.NET WebHooks receiver shines! It will parse the notification for you, exposing strong typed objects you can work with. All you need to do is modify the method/function signature you get withe template to use the SalesforceNotifications type, making sure you're referencing the required assembly (Microsoft.AspNet.WebHooks.Receivers.Salesforce, which is made available to you, so no need for package reference) and namespace reference (Microsoft.AspNet.WebHooks).
Here is a full sample of a function that will receive the request and log the Organization ID, Action ID, grab the first notification and log all of its properties:
#r "Microsoft.AspNet.WebHooks.Receivers.Salesforce"
using Microsoft.AspNet.WebHooks;
public static void Run(SalesforceNotifications req, TraceWriter log)
{
log.Info($"Salesforce webhook was triggered!");
log.Info(req.OrganizationId);
log.Info(req.ActionId);
var notification = req.Notifications.First();
foreach (var p in notification.Keys)
{
log.Info($"{p} = {notification[p]}");
}
}
This process will be a lot smoother when the receiver is officially supported, but even with the added steps, this still beats having to parse the SOAP messages yourself :)
I hope this helps!