In am trying to get an access token to call Salesforce Marketing Api through FuelSDK the code is:
NameValueCollection parameters = new NameValueCollection();
parameters.Add("clientId", "myclientidvalugoeshere");
parameters.Add("clientSecret", "myclientsecretvaluegoeshere");
var client = new ETClient(parameters);
ETFolder folder = new ETFolder();
folder.AuthStub = client;
var response = folder.Get();
return response.Message;
But it's returning:
System.Net.WebException : The remote server returned an error: (401) Unauthorized.
I am not really sure if I am doing it the right way.
What I really want to do is to connect to Salesforce Marketing cloud through FuelSDK C#, using Oauth authentication to get access token for the user and call the resources needed.
You probably need to add authEndPoint, restEndPoint, as well as useOAuth2Authentication to your NameValueCollection parameters.
Check this out: https://github.com/salesforce-marketingcloud/FuelSDK-CSharp/wiki
There's a feature called whitelist. Try to add there Your IP and also double check that You are using the correct API Keys.
From my experience the response You are receiving is becasue the combination of API key strings are not the correct ones.
I would recommend that You try the same keys to do a simple REST API request on the same package. Find more on this here.
Related
I managed to get the access_token and refresh_token on front end and now its stored in a database, On the backend .netcore application I create googlecredential with
var cred=googleCredential.fromAccessToken(access_token);
but this one doesn't refresh on its own and I have no idea how to refresh this. I can send a post request to their rest api and refresh it but I need to know when "creds" has expired to send that refresh request. PS know that the tokens are in a database so using anything but .fromaccesstoken is not an option.
EDIT:
Complete code can not be shared but here's how the application's flow is going. On a reactJS application I get the authorization code via react-google-login module
<GoogleLogin
clientId="xxx"
buttonText="Login"
onSuccess={this.responseGoogle}
onFailure={this.responseGoogle}
cookiePolicy={"single_host_origin"}
scope="https://www.googleapis.com/auth/drive.readonly"
accessType="offline"
prompt="consent"
responseType="code"
/>
this returns an authorization code as the only response body, this response is then used with another endpoint to exchange for refresh and access token at front end, these tokens are sent to a backend endpoint which stores them in a db. Now the server side can create a googlecredential object via
this.googleCredentials=GoogleCredential.FromAccessToken(this.googleAccessToken);
Only problem being this doesnt handle the refreshing on its own so you have to somehow implement it.
Since I can't find another way to refresh when GoogleCredentials object is created via fromtoken(ACCESS_TOKEN) what I've done is sending a post request with the refresh token that I have to the rest endpoint at the backend and get a new access_token.
Another problem faced was finding out when the access token was expired for which no solution could be found. But it returns a 401 exception at creating the drive folders via drive service in my case
var res = await this.driveService.Files.Create(folder).ExecuteAsync()
here res will raise an exception and I just put it in a try block and got the new access token via http request in catch and ran the statement again (hint: recursion)
Hope this helps anyone, but better proposed solutions will be welcomed. Please understand that this is going to be a backend solution reading refreshtoken from database.
I have configure dropbox developer API in c#. and pass token and secretkey in below method.
OAuthToken oauth = new OAuthToken(DropboxAccessToken,DropboxAccessSecretKey);
var api = new DropboxApi(ConsumerKey, ConsumerSecret, oauth);'''
var account = api.GetAccountInfo();
Last statement raise "The remote server returned an error: (401) Unauthorized" this error.
Please help me how to solve this and please let me know if any missing condition or steps.
Based on the code you shared, it looks like you're trying to use OAuth 1 with Dropbox API v1. (OAuth 1 uses separate access token key and secrets parts, whereas OAuth 2 uses a single bearer access token. Also, the GetAccountInfo method name indicates Dropbox API v1.)
Dropbox API v1, along with the use of OAuth 1 with it, are retired now. You should instead use Dropbox API v2 with OAuth 2. For .NET, we recommend using the official Dropbox API v2 .NET SDK. It includes instructions for getting started, full documentation, and example apps.
I want to access NiFi and do some actions through external web application created in C# using proxy user request. For that,
I have created C# web application and hosted as secure connection(https).
I need to access NiFi components using its REST API service without authorization token. Added C# web application certificate into NiFi truststore and added certificate name as user (CN=machineName) in NiFi. Also, added "proxy user request" policy for the newly added user.
In C# web application, added "X-ProxiedEntitiesChain = <username>" in header while requesting NiFi API. But it returns "unknown user" error in response. Please find the sample code below,
var httpWebReq=(HttpWebRequest)WebRequest.Create("https://testhost:8080/nifi-api/access");
httpWebReq.Headers["X-ProxiedEntitiesChain"] = "<username>";
httpWebReq.Method = "GET";
var response = (HttpWebResponse)httpWebReq.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
return responseString;
Based on the available information the most likely problem is that you are not using a properly authorized user.
Check that you are using the proper username, and confirm that it is actually authorized for access.
(And of course make sure you don't just pass the string "username")
How to call Azure functions on azure from a Windows Application running on local machine, without embedding the keys in the Application?
Is there a Client Proxy Generator like the one for WCF Services but for Azure functions instead? or do you just use web client ?
You can use Restsharp to access an Azure Function.
You will need to get the full Url containg the host key from the portal.
Navigate to your function in the portal.
Use the </> Get function URL link for the function to get the full URL (next to the Run button at top of page). The key is after "code="
var fullUrl = "https://myfunciton1000.azurewebsites.net/api/ResourceGroupNameExists?code=ENp/dFAluLqHM8TDr...Sk5YJ7DSEbs0PHPzTVw==";
var url = "https://myfunciton1000.azurewebsites.net/api";
var securityCode = "ENp/dFAluLqHM8TDr...YJ7DSEbs0PHPzTVw==";
var client = new RestSharp.RestClient(url);
var request = new RestSharp.RestRequest("ResourceGroupNameExists", RestSharp.Method.POST);
request.AddHeader("x-functions-key", securityCode);
request.AddQueryParameter("ResourceGroupName", "ImageStormSource");
var response = client.Execute(request);
Calling an Azure function from a .NET application is simply a matter of issuing an HTTP request to the endpoint: https://social.msdn.microsoft.com/Forums/azure/en-US/2c676980-8dd3-4112-ae41-a2c4f4825fe3/how-to-call-a-azure-function-from-aspnet-webhook?forum=AzureFunctions
The communication between Azure and the client application is encrypted using SSL.
As far as the key is concerned, you could either hard-code it into your client code or configuration or retrieve it from some service of yours.
If your azure function app is using HttpTrigger it is no different than any non Azure WebAPI app. You call it via a rest client using either just basic a HttpClient or a wrapper library like RestSharp.
There is nothing special you have to deal with, go find any tutorial on how to call a WebAPI app for more information.
I have a WCF Rest service that I am trying to integrate with Azure's ACS in order to validate requests from the clients.
I am trying to use one of the tests placed here :
http://msdn.microsoft.com/en-us/library/windowsazure/hh674475.aspx#BKMK_1
This is my code :
string wrapUsername = "account#hotmail.com";
string wrapPassword = "aPass123";
// request a token from ACS
WebClient client = new WebClient();
client.BaseAddress = string.Format("https://glamstsecure.accesscontrol.windows.net");
NameValueCollection values = new NameValueCollection();
values.Add("wrap_name", wrapUsername);
values.Add("wrap_password", wrapPassword);
values.Add("wrap_scope", "uri:WindowsLiveID");
byte[] responseBytes = client.UploadValues("WRAPv0.9/", "POST", values); <- Here i am getting The remote server returned an error: (401) Unauthorized
Scope is supposed to be the authentication authority right?
wrap_scope should be the realm of your relying party application in the ACS portal.
Also, you may want to take a closer look at this solution. It's intended to be used with service identities that you configure in your ACS namespace.
Ia m runing into the same issue when trying to use GoogleId/password. it works fine for ServiceIdentity. But always throws a 401 error when using anything else. Also, Rick Rainey, Can you please elaborate on why the above code can only be used for ServiceIdentities as specified by you?