IBM.WatsonDeveloperCloud Asp.Net package - asp.net

I would like to use IBM Watson Conversation service to build a chatbot web application in the Asp.Net platform. I installed IBM.WatsonDeveloperCloud Asp.Net package today, but have no idea what I should do with it and there is no document. There are about 50 projects in the solution, which one can be used for the so called simple chatbot web application?

Watson Developer Cloud has all the documentation that you need to use Watson Services, include Conversation Service.
Here are some examples to use Conversation:
Installation
Nuget
PM > Install-Package IBM.WatsonDeveloperCloud.Conversation.v1
Project.json
"dependencies": {
"IBM.WatsonDeveloperCloud.Conversation.v1": "1.2.0"
}
Usage
You complete these steps to implement your application: Configure a workspace. With the easy-to-use graphical environment, you set up the dialog flow and training data for your application. Develop your application. You code your application to connect to the Conversation workspace through API calls.
Instantiating and authenticating the service
Before you can send requests to the service it must be instantiated and credentials must be set.
// create a Conversation Service instance
ConversationService _conversation = new ConversationService();
// set the credentials
_conversation.SetCredential(<username>, <password>);
Send message:
// create message request
MessageRequest messageRequest0 = new MessageRequest()
{
Input = new InputData()
{
Text = <input-string0>
}
};
// send a message to the conversation instance
var result0 = _conversation.Message(<workspace-id>, messageRequest0);
// reference the message context to continue a conversation
messageRequest messageRequest1 = new MessageRequest()
{
Input = new InputData()
{
Text = <input-string1>
},
Context = result.Context
};
// Send another message including message context.
result1 = _conversation.Message(<workspace-id>, messageRequest1);
Obs.: In this link have one full guide step-by-step to use Watson Conversation Service with .Net.
See the Official Documentation for .Net SDK
One good Tutorial Video Guide to Integrating Watson Conversation in your Application.
See the Official API Reference for use Watson Conversation Service (You can have a base with this link).

Related

ADFS 2016 On behalf of flow : cannot get any user informations

I'm trying to implement the "on behalf of" flow in an application using ADFS 2016 as STS. As a reference, I look at this Microsoft tutorial (https://learn.microsoft.com/en-ca/windows-server/identity/ad-fs/development/ad-fs-on-behalf-of-authentication-in-windows-server). It's working as it should, I can login into my web application and then use my original access token in UserAssertion to generate a new access token with the proper audience to call my API BUT I found absolutely no way to include any user informations (sub, name, email, upn etc.) into the access token for my API, even if I set claim rules into my ADFS configurations for the API.
I checked the communication between my app and adfs using Fiddler and everything looks like the informations in the tutorial. See the screen shot of the "on behalf of" request below :
Here's the resulting access token :
Finally, here's the code I use to generate my new access token :
private async Task<string> GetAccessToken(ClaimsPrincipal user, string originalAccessToken)
{
var authority = "[authority]";
var context = new AuthenticationContext(authority, false);
string userName = user.FindFirstValue("upn");
var userAssertion = new UserAssertion(originalAccessToken, "urn:ietf:params:oauth:grant-type:jwt-bearer",userName);
var cc = new ClientCredential("https://localhost:44387/", "[client_secret]");
var result = await context.AcquireTokenAsync("https://localhost:44339/", cc, userAssertion);
return result.AccessToken;
}
Have you struggle with that scenario and if yes, did you find a way to fix this ?
Thanks
I've only used the Microsoft On Behalf Of flow with Azure AD and not ADFS, but it looks like you need to send a more detailed scope in your User Info request.
Maybe try sending 'openid profile email', to indicate that you want that type of detail, as in Section 17 of my blog post. Of course this assumes that this type of data has been registered for all users.
TROUBLESHOOTING
Looks like one of these will be the cause:
A suboptimal Microsoft library that does not allow you to send the required scope
Or ADFS 2016 perhaps lacks the scope features that work correctly in Azure AD
I would concentrate on making extra sure you are sending the correct form URL encoded request message, using a tool such as curl, Postman or a plain C# HttpClient. Here is the code I used to send the correct scope - using an open source library rather than a Microsoft one:
Sample NodeJS Code
If you can get the scope sent correctly then you should have a resolution either way:
Either you get the correct data and can update your code
Or the behaviour you want is not supported by ADFS
Good luck ...

Calling Microsoft graph API from dotnetcore app returns NotFound

I'm trying to get items from SharePoint using the Graph API in the name of the user, all these done inside a .net core 3.1 web app using oauth. When I request for specific items in a SharePoint document library I get the following ServiceException:
ex = {"Code: itemNotFound\r\nMessage: The resource could not be found.\r\nInner error:\r\n\tAdditionalData:\r\n\trequest-id: 7605d475-5967-481e-a16c-ab1fad610ef9\r\n\tdate: 2020-04-15T21:27:48\r\nClientRequestId: 7605d475-5967-481e-a16c-ab1fad610ef9\r\n"}
My calling function is the following:
var searchResult = await graphServiceClient
.Sites[$"{SharePointSiteId}"]
.Drives[$"{SharePointDocumentLibraryId}"]
.Items[$"{InvoicesFolderId}"]
.Children
.Request()
.GetAsync();
where:
SharePointSiteId is a fully qualified SPS site Id
SharePointDocumentLibraryId id of the document library
InvoicesFolderId id of the folder in which I'd like to enumerate the children elements
The strange is that until I request for the Drive only:
var searchResult = await graphServiceClient
.Sites[$"{SharePointSiteId}"]
.Drives[$"{SharePointDocumentLibraryId}"]
.Request()
.GetAsync();
everything goes fine.
Strange thing 2: If I call the API using the Graph explorer with the same user in the same time using the Item identifier {InvoicesFolderId}, it gives back its children well.
Needless to say, the user can login to the SPS site and do whatever she wants. :)
I am able to reproduce the same exception thrown when calling from Graph .Net SDK in C#. Taking the exact same URL that is generated by SDK and testing in Graph Explorer is successful as well. I would recommend opening an issue on the Graph .Net SDK repo.

owin active directory token validation random slowness and error

I am facing some random authorisation problem when using following code to authenticate against ad active directory (I have a web api).
I believe this code will send a validation request to our azure active directory, but randomly we got validation error and some times it can take a while to get validation result back.
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = Constants.AzureActiveDirectoryTenant,
TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = true,
// These values will be checked against what is received in the access token.
ValidAudiences = Constants.AzureActiveDirectoryValidAudiences
}
});
Is it possible to understand why validation failed? Also about the speed, is it possible to create some custom method to cache a token on my web site? So I don't need to validate every request to AD all the time.
You can try the Microsoft.Owin.Diagnostics nuget package to check the logs.
Alternatively, for a remote debug:
In Cloud Explorer in visual studio, find you web app and select "Remote Debugging."
Then publish your site in Debug mode.
In the portal, enable it by going to Application settings > Debugging > Remote Debugging > On

Nodejs: firebase.auth().signInWithCustomToken(token) generate "Object has no method 'signInWithCustomToken'" error

With new firebase version, y need to access by node.js at my firebase application.
var firebase = require("firebase");
var parms={.......}
firebase.initializeApp(parms);
var token = firebase.auth().createCustomToken('123'); //Token generated successfully
//Line below throws error
firebase.auth().signInWithCustomToken(token).catch(function(error) {
//do something
});
If I use signInWithCustomToken from javascript in the browser, it works fine. But if I use it from command line: node file.js, it throws the error: firebase.auth().signInWithCustomToken(token) generate "Object has no method 'signInWithCustomToken'" error
Why?
On this part the web and node apis are different.
As stated in the Upgrade Guide (https://firebase.google.com/support/guides/firebase-web#update_your_authentication_code_numbered)
you need to use a service account for node.js apps. A good point to start is this page: https://firebase.google.com/docs/database/server/start#section-account
I would have loved to paste you the links to the auth api pages, but I'm only allowed to post 2 links. :)

Calling google cloud endpoint api from another google app engine web application servlet java

I have a google cloud endpoint api application which i want to call it from another google app engine web application, say from a servlet. The cloud endpoint api is not secured.
I tried looking for examples but could not find one. I see example related to Android client.
When tried using URLConnection it does not work, am not sure whether am doing correctly as well, sample codes or pointers will be of great help. I also checked the logs of cloud endpoint api to see if any requests are coming through, but i don't see any errors in the logs.
I'm doing this as well, although with authentication. You can use the Jar generated by the endpoint API at MyAPI/build/libs/MyAPI-v1-SNAPSHOT.jar, just as you might in Android.
Once you depend on that JAR, your code to build an API client should look something like that below. Mine is using OAuth authentication with a service account, which I'll leave in there because it was the more complicated part which you might eventually need. But without authentication you should just be able to set the credential to null.
HttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
List<String> SCOPES = Arrays.asList(EMAIL_SCOPE);
String SERVICE_ACCCOUNT_ID = "my-account-id#my-app.iam.gserviceaccount.com";
String CREDENTIAL_FILE = "WEB-INF/my-file.p12";
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(SERVICE_ACCCOUNT_ID)
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(new File(CREDENTIAL_FILE))
.build();
MyAPI.Builder builder = new MyAPI.Builder(
HTTP_TRANSPORT,
JSON_FACTORY, credential)
// options for running against local devappserver
// - 10.0.2.2 is localhost's IP address in Android emulator
// - turn off compression when running against local devappserver
.setRootUrl("http://localhost:8080/_ah/api/")
// .setRootUrl("https://my-appengine-url.appspot.com/_ah/api")
MyAPI myAPI = builder.build();
You cannot use URLConnection for making endpoint calls from App Engine. Use FetchURL instead. If you set doNotFollowRedirect, you will receive X-Appengine-Inbound-Appid as header in the called App Engine project. You can trust this header, as Google would strip it off if somebody off App Engine would use it. Make sure you target the yourproject.appspot.com domain, as it won't work with custom domains.
https://cloud.google.com/appengine/docs/java/appidentity/

Resources