hope you are doing well !
I have been trying to write a GraphQL Mutation Resolver for a REST POST request in Azure APIM but nothing is working so far.
The REST call takes an object with firstName, lastName, username, password and returns an object with the same fields.
Below is my current code. Any Help would be appreciated.
<set-graphql-resolver parent-type="Mutation" field="createUser">
<http-data-source>
<http-request>
<set-method>POST</set-method>
<set-url>[URL]</set-url>
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body>#{
var args = context.Request.Body.As<JObject>(true)["arguments"];
JObject jsonObject = new JObject();
jsonObject.Add("firstName", args["firstName"]);
jsonObject.Add("lastName", args["lastName"]);
jsonObject.Add("username", args["username"]);
jsonObject.Add("password", args["password"]);
return jsonObject.ToString();
}</set-body>
</http-request>
</http-data-source>
</set-graphql-resolver>
UPDATE:
This is the schema i am using:
And this is how i am testing the mutation with the arguments and the original error i am getting:
In Application insights, i am getting this error log:
NOTE: This is the original response that i'm getting from a normal REST Request
Thank you!
I contacted Microsoft about this issue and they told me that it is a bug on the service side.
The product team is working on the fix and it will be released in v.33 (4 to 6 weeks).
Related
I'm creating an app and need the information about the user projects. When I request that for me, a administrator in the organization, the request goes without a problem. When other users request something it gives the 203 code.
I'm using the following code:
var personalaccesstoken = token;
using var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
Encoding.ASCII.GetBytes(
$#"{""}:{personalaccesstoken}")));
using var response = await client.GetAsync(
"https://dev.azure.com/{organization}/_apis/projects?api-version=2.0");
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
I'm using Oauth to get the token.
Does anyone know why this is not working?
The 203 error code normally caused by an incorrect PAT format. Looks like you are probably failing authentication because the PAT did not be encoded with base64 correctly.
You need to ask the users to check the PAT in their code to see whether it is correct, or generate a new PAT and replace it in the code to see whether the issue would be fixed.
I need advice on what I'm doing wrong. I'm calling the following block of code from a console application in C#:
string path = # "C:\Temp\private.key";
ApiClient apiClient = new ApiClient();
var authToken = apiClient.RequestJWTUserToken (
"11383d14-8c83-4c61-ab4f-99d5d19bd2dd",
"476205fe-9d1a-46be-95e3-6873315ce3a9",
"account-d.docusign.com",
File.ReadAllBytes(path),
1,
new List<string>
{
"signature",
"impersonation"
});
Error is: "consent_required"
I have authentication set to "Authorization Code Grant".
What's wrong in the parameters or settings?
Thank you
This is right, you need to obtain consent and we have plenty of documentation about it.
https://www.docusign.com/blog/developers/oauth-jwt-granting-consent
https://developers.docusign.com/platform/auth/jwt/jwt-get-token/
If still you feel some documentation is not clear about JWT consent - can you let me know which one?
Currently we have the front end sending files to an Azure storage account into specific blob containers. The front-end is manually getting SAS tokens put into the build via a person getting a SAS from the storage account and pasting it into the front-end code so it can read and write to the storage account.
We're wanting to have the front-end send a request to APIM with a file. We then want to hash that file, use that hash as the name and store it in azure blob storage. I'm new to Azure API Management, is this even possible? It seems like I can't get at the uploaded file.
In APIM policies I currently have the Authorization to the storage account working but I can't figure out how to get at the Request.Files like I normally would in an MVC app.
I've been looking all over https://learn.microsoft.com/ as well as https://techcommunity.microsoft.com/ and SO and I've even started looking on the second page of Google search results. I can't find anything that points to this being possible or not.
Here is my current policy. It works in the sense that the front-end can hit it and pass through a file and that file is saved. But we want to hash the file and use that hash as the name to avoid name collisions in the Azure storage account blob container
<policies>
<inbound>
<base />
<set-variable name="UTCNow" value="#(DateTime.UtcNow.ToString("R"))" />
<set-variable name="Verb" value="#(context.Request.Method)" />
<set-variable name="documentstorage" value="{{documentstorage}}" />
<set-variable name="documentstoragekey" value="{{documentstorageaccesskey}}" />
<set-variable name="version" value="2019-12-12" />
<set-variable name="bodySize" value="#(context.Request.Headers["Content-Length"][0])" />
<set-variable name="contentType" value="#(context.Request.Headers["Content-Type"][0])" />
<set-header name="x-ms-version" exists-action="override">
<value>#((string)context.Variables["version"] )</value>
</set-header>
<set-header name="x-ms-blob-type" exists-action="override">
<value>BlockBlob</value>
</set-header>
<set-header name="date" exists-action="override">
<value>#((string)context.Variables["UTCNow"])</value>
</set-header>
<set-header name="Authorization" exists-action="override">
<value>#{
var account = (string)context.Variables["documentstorage"];
var key = (string)context.Variables["documentstoragekey"];
var verb = (string)context.Variables["Verb"];
var container = context.Request.MatchedParameters["container"];
var fileName = context.Request.MatchedParameters["fileName"];
var dateNow = (string)context.Variables["UTCNow"];
string contentType = (string)context.Variables["contentType"];//"application/pdf";
var contentLength = (string)context.Variables["bodySize"];
var stringToSign = string.Format("{0}\n\n\n{1}\n\n{2}\n{3}\n\n\n\n\n\nx-ms-blob-type:BlockBlob\nx-ms-version:{4}\n/{5}/{6}/{7}",
verb,
contentLength,
contentType,
(string)context.Variables["UTCNow"],
(string)context.Variables["version"],
account,
container,
fileName);
string signature = "";
var unicodeKey = Convert.FromBase64String(key);
using (var hmacSha256 = new HMACSHA256(unicodeKey))
{
var dataToHmac = Encoding.UTF8.GetBytes(stringToSign);
signature = Convert.ToBase64String(hmacSha256.ComputeHash(dataToHmac));
}
var authorizationHeader = string.Format(
"{0} {1}:{2}",
"SharedKey",
account,
signature);
return authorizationHeader;
}</value>
</set-header>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
I haven't tried this but it sounds like you can get the request body (that's where I assume your file is):
var inBody = context.Request.Body.As<byte[]>(preserveContent: true);
Based on this: https://learn.microsoft.com/en-us/azure/api-management/api-management-policy-expressions#ref-imessagebody and this https://learn.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#SetBody
However, if you just want to get a unique files names, why not simply generate a GUID? Or do you mean you want to make sure that every file only gets uploaded once? (Then hashing probably makes sense)
In my loopback application i am getting the current logged-in user using currentcontext as follows..
exports.getCurrentUserId =function(){
var ctx = loopback.getCurrentContext();
var accessToken = ctx && ctx.get('accessToken');
var userId = accessToken && accessToken.userId;
return userId;
}
When i am calling this method getCurrentUserId, its working fine sometime, sometimes its giving null. Its unpredictable . Please share your ideas. Thanks in advance.
versions:
loopback-connector-mongo:1.15.1
Re. getCurrentContext(), there is a plan to deprecate this method as it has been unreliable ( see discussion here).
However, there is a suggested workaround to inject Remote Context via Options.
Im tring to user the DocuSign api/sdk to send a document for someone to sign. The examples say something like:
//.NET
APIServiceSoapClient apiService = new APIServiceSoapClient();
apiService.ClientCredentials.UserName.UserName = "Your DocuSign UserName here";
apiService.ClientCredentials.UserName.Password = "Your DocuSign Password here";
Which I of course have tried but its not working.
I get the following error:
Security requirements are not satisfied because the security header is not present in the incoming message.
Ive tried
var username = "myemail";
var pass = "mypass";
var iteratorKey = "iteratorkey";
APIServiceSoapClient apiService = new APIServiceSoapClient();
apiService.ClientCredentials.UserName.UserName = username;
//also tried ...UserName = "[" + iteratorKey + "]" + username;
apiService.ClientCredentials.UserName.Password = pass;
Is this not where all security requirements are met? maybe? Using APIService not DSAPIService if that makes a difference.
I ended up having to use a different way to pass in the credentials. Which I found somewhere else. Im still not sure how to correctly use the other method I tried though so if anyone knows how to use the other method it would be great just because the code is neater and easier to follow.
string auth = #"<DocuSignCredentials>
<Username>email</Username>
<Password>pass</Password>
<IntegratorKey>key</IntegratorKey>
</DocuSignCredentials>";
DSAPIServiceSoapClient apiService = new DSAPIServiceSoapClient();
using (var scope = new System.ServiceModel.OperationContextScope(apiService.InnerChannel))
{
var httpRequestProperty = new System.ServiceModel.Channels.HttpRequestMessageProperty();
httpRequestProperty.Headers.Add("X-DocuSign-Authentication", auth);
System.ServiceModel.OperationContext.Current.OutgoingMessageProperties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] = httpRequestProperty;
EnvelopeStatus envStatus = apiService.CreateAndSendEnvelope(envelope);
return envStatus.EnvelopeID;
}
There are two ways to pass member credentials through DocuSign's SOAP API (as opposed to the newer REST API):
SOAP Header via WS-Security UsernameToken
HTTP Header via a custom field “X-DocuSign-Authentication”
The Account Management API only supports the HTTP Header authentication method, while all others can support either method.
Additionally, the DocuSign SOAP API has two API end points: API.asmx and DSAPI.asmx. The API.asmx end point requires the WS-Security UsernameToken in the SOAP header authentication. The DSAPI.asmx and AccountManagement.asmx end points require the HTTP Header authentication method.