I feel I must be missing something obvious here. I've been trying to follow the instructions at https://learn.microsoft.com/en-us/bing/search-apis/bing-visual-search/quickstarts/sdk/visual-search-client-library-csharp. I created a "Bing Search" service in Azure with the S9 tier which supports Visual Search. I went to the Keys and Endpoint section and copied the Key 1 out and put it in the below code, yet every time I run it I get Unauthorized:
{"code":"401","message": "Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}
var client = new VisualSearchClient(new Microsoft.Azure.CognitiveServices.Search.VisualSearch.ApiKeyServiceClientCredentials("<key>"));
ImageInfo ImageInfo = new ImageInfo(url: "https://media.vanityfair.com/photos/5d9f5be40fa2040008f28470/4:3/w_1776,h_1332,c_limit/always-sunny-in-philadelphia-hangs-in-there.jpg");
VisualSearchRequest VisualSearchRequest = new VisualSearchRequest(imageInfo: ImageInfo);
var result = await client.Images.VisualSearchMethodAsync(knowledgeRequest: JsonConvert.SerializeObject(VisualSearchRequest));
The instructions don't say anything about setting an endpoint, but I tried that too, setting the Endpoint property from the one in my Keys and Endpoint page:
client.Endpoint = "https://api.bing.microsoft.com/";
But that just result in a NotFound error.
Anyone have any idea what's going on? I tried both keys with no success. Here's a LINQPad repro of the issue: http://share.linqpad.net/c3p8vo.linq
Thanks!
I figured out the issue. The documentation is actually wrong (as of 8/9/22). It says
The NuGet Visual Search package.
From the Solution Explorer in Visual Studio, right-click on your project and select Manage NuGet Packages from the menu. Install the Microsoft.Azure.CognitiveServices.Search.VisualSearch package.
But that's the old nuget package, which has the old endpoint in it: https://api.cognitive.microsoft.com. The new endpoint is https://api.bing.microsoft.com. I found that there's actually another, newer nuget package, Microsoft.Bing.Search.VisualSearch which has the correct endpoint, but I can't find documentation anywhere pointing to it!
Once I switched to that nuget package though, everything worked as expected when passing an imageUrl. I still can't get it to work with a FileStream though, I think that might be broken as well.
Related
We have a Xamarin.Forms application that I am trying to upgrade to MSAL (has been using ADAL up until now) in order to authenticate users that exist in our Azure Active Directory. The app uses the Prism framework. It seems I am able to use MSAL and authenticate using the app on Android, but when trying to log in on the UWP version, I get an error stating that msedge cannot be opened:
msedge.exe error "Windows cannot access the specified device, path or file."
This occurs when AcquireTokenInteractive is called on the PublicClientApp.
public Task<IAuthMSAL> AcquireTokenInteractiveAsync(string[] scopes)
{
var options = new SystemWebViewOptions() { OpenBrowserAsync = SystemWebViewOptions.OpenWithChromeEdgeBrowserAsync };
return PublicClientApp.AcquireTokenInteractive(scopes)
.WithParentActivityOrWindow(ParentWindow)
.WithUseEmbeddedWebView(false)
.WithSystemWebViewOptions(options)
.ExecuteAsync()
.ConvertToProvider();
}
For reference, the PCA is being built just as I've seen it be built in a lot of documentation that I've read:
AuthenticationService.PublicClientApp = PublicClientApplicationBuilder
.Create(config.ClientId)
.WithAuthority(config.Authority)
.WithDefaultRedirectUri()
.WithBroker()
.Build();
Since the error message alludes toward a permission issue or missing executable file, I've ensured that msedge.exe is available in the location shown in the title of the error, and edited the security on the msedege.exe allowing full control on all principals listed (right clicking the executable, selecting properties, security tab) to see if that would help, but it did not.
I've also tried various extension methods on the PublicClientApplicationBuilder class, such as modifying the redirect uri, trying different NuGet packages that go along with Microsoft.Identity.Client (such as .Desktop and .Broker), and also the various methods on IPublicClientApplication, such as WithSystemWebViewOptions, WithUseEmbeddedWebView, etc.
Has anyone else experienced issues when trying to use MSAL with Prism, on UWP specifically? I'm wondering if it is an issue between the two libraries. I have a sample UWP project that does not use Prism, and there are no issues there.
Thanks in advance to anyone that is able to provide some insight on this issue.
Is there a tutorial on how to properly call a cloud function using Xamarin.Firebase.iOS.CloudFunctions? Or how to setup a regular http request for it, without the library?
I set up my function like this:
exports.IsAppleSubscriptionActive = functions.https.onCall(async (data, context) => {});'''
and deployed it like this:
firebase deploy --only functions
and got and url like this:
https://[region]-[project-id].cloudfunctions.net/IsAppleSubscriptionActive
On the client I installed the nuget and I try calling:
var result = await CloudFunctions.DefaultInstance.HttpsCallable("IsAppleSubscriptionActive").CallAsync(payloadToSend);
where payloadToSend is a NSDictionary.
I get
Foundation.NSErrorException: Error Domain=com.firebase.functions Code=13 "INTERNAL" UserInfo={NSLocalizedDescription=INTERNAL}
What am I missing? I feel like the native tutorials aren't helping either.
When using a regular http request I get a 500 status, in the logs I see something related to permissions accessing the secret manager (I use it for some api keys).
Ok, so there was nothing wrong with the code, I just wasn't giving the proper permissions to the proper user (I was using Secret Manager in my cloud function)
I'm trying to connect to the Google Datastore on my account with service account credentials file (which I've created according to the documentation), but I'm encountering with authentication error while trying to insert an entity:
Grpc.Core.RpcException: Status(StatusCode=Unauthenticated,
Detail="Exception occured in metadata credentials plugin.")
My code is:
var db = DatastoreDb.Create("myprojectid");
Entity entity = new Entity{
Key = db.CreateKeyFactory("mykindname").CreateIncompleteKey()
};
var keys = await db.InsertAsync(new[] { entity });
The GOOGLE_APPLICATION_CREDENTIALS variable refers to the credentials file and when calling GoogleCredential.GetApplicationDefaultAsync() to see if the credentials object is valid it indeed looks good...
I saw some earlier examples which used the GetApplicationDefaultAsync function togehether with some DatastoreService object - but I couldn't find the DatastoreService object (probably it was there in old versions...) in the latest .Net API: Google.Cloud.Datastore.V1
Notice that I don't want to use the other authenticaiton methods:
1) Using the gcloud cli.
2) Running from Google environment (app engine for example).
Any idea how to solve this?
After the great help of Jon Skeet the issue was solved.
The authentication issues can occur if you don't reference all the required Datastore dlls. Make sure that all the dlls are referenced on the project that are running the calls to the Datastore.
I've added the Google Datastore lib via the NuGet to my test project and everything worked!
Notice that in such cases it is recommended to enable gRPC logging. `(For exmaple: GrpcEnvironment.SetLogger(new ConsoleLogger()), there you'll probably see if there were issues loading several dlls...
Authentication can be broken if your system clock is significantly incorrect. Check your system time, and fix it if necessary, then try authenticating against Datastore again.
I am new to Trello.Net and struggling a little with authorisation. I understand the process, of requesting a URL and then asking the user to browse to that URL to get a token.
The first problem is I am trying to write a process which runs automatically without any UI. So I'm having to use a hard coded token, which I obtained by running this code to get a URL, which I then browse to manually. I would rather do this part automatically (get the resulting token programatically, not by having the user browse somewhere):
ITrello trello = new Trello(Key);
var url = trello.GetAuthorizationUrl("TrelloCapture", Scope.ReadWrite, Expiration.Never);
Console.WriteLine(url);
This URL, when I browse to it, displays for me a token which, for now, I hardcoded into my application as follows:
var token = "[the token copied and pasted from the web page]"
I then authorise using:
trello.Authorize(token);
Which seems to work fine. Next I want to access some basic data, and this is where my second problem comes in.
// Get the authenticated member
Member me = trello.Members.Me();
Console.WriteLine(me.FullName);
Members.Me() returns null every time. The same problem with Cards.ForMe() and other methods. Everything is null. Why?
What am I doing wrong?
I found the answer. I fixed it by getting the latest versions of these NuGet packages in my solution:
Trello.Net
JSON.Net
RestSharp
After getting those latest versions I was seeing proper values instead of null in the trello objects.
Hope this helps somebody who reads this.
Had the same problem, above answer helped me.
Though I couldn't get the latest but had to use:
"RestSharp" version="104.1
"Newtonsoft.Json" version="6.0.1"
Since The nuget also doesn't have the correct color enum i had to download the project and make my own changes.
I am attempting to implement the example from the DotNetOpenAuth Service Provider solution but instead of using OpenId for authentication, I am using Forms Authentication.
I copied and pasted the Consumer example but removed the Service Reference and added a new service reference pointing to my WCF service.
Getting of the Access Tokens is working great and I can see them appearing in my database table, however, as soon as I attempt to access data, it is failing on this line in the OAuthAuthorizationManager class:
Uri requestUri = OperationContext.Current.IncomingMessageProperties["OriginalHttpRequestUri"] as Uri;
Is there something I am missing somewhere? It seems that this property should exist because I don't see where it is manually added anywhere in the original. I copied and pasted the Web.config from the sample Service Provider project and all of my files are named the same.
Let me know if there is any more information needed or if anyone wants me to email them the sample project to look at.
Thanks for any assistance.
Uri requestUri = operationContext.RequestContext.RequestMessage.Properties.Via;
I think it is a more secure way of finding the original HTTP information.