Creating JWT custom claims in DataPower - jwt

Running on DataPower 7.5.2.0
I created a JWT Generator as part of a AAA Policy and it is working fine, I am able to generate, sign and then externally verify the JWT with no issues.
Now I want to add a custom claim to the JWT, so I ticked the box for Custom and then uploaded this Gateway script file:
var claim = {
"result" : {
"user" : "hardcode"
}
};
session.output.write(claim);
and it generates the correct JWT with the user attribute. However when I try to add a second value to it like so:
var claim = {
"result" : {
"user" : "hardcode",
"name" : "myname"
}
};
session.output.write(claim);
I now get this error:
[Error: Required CustomClaim Name or Value field missing] errorMessage: 'Required CustomClaim Name or Value field missing', errorCode: '0x8580005c', errorDescription: 'GatewayScript console log message.', errorSuggestion: 'GatewayScript console log message. Refer to the message for more information.'
Which is the same message I got before I realized I had to set the output to result from the InfoCenter's vague documentation.
How do I add multiple custom claims in the JWT Generator Gateway script??

It would appear that DataPower only allows you to add a single custom claim, so you just need to make that a complex object like so:
var claim = {
"result" : {
"claim" : {
"user" : "hardcode",
"one" : true,
"clientId" : "asdf-asdf-asdf",
"endpoint" : "http://192.168.142:8080/member/ws"
}
}
};
session.output.write(claim);
This then generates the correct JWT with a nest claim.
eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGljIiwic3ViIjoiYWRtaW4iLCJleHAiOjE0ODIyNjU5ODQsImlhdCI6MTQ4MjI2MjM4NCwianRpIjoiZDhjNTE1ZDEtZmVjMS00ZGVmLThiNDctZmYzY2E2OWVjOWRiIiwibm9uY2UiOiJtN2lVZlBqTCIsImF1ZCI6ImlkMSIsImNsYWltIjp7InVzZXIiOiJmcmVkIiwib25lIjp0cnVlLCJjbGllbnRJZCI6ImFzZGYtYXNkZi1hc2RmIiwiZW5kcG9pbnQiOiJodHRwOi8vMTkyLjE2OC4xNDI6ODA4MC9tZW1iZXIvd3MifX0.viakwnM5bhhmGIn0QmDJTmsWCuIciO2BOdUVyxYpsFA

Related

Get a value of item in the array

I have a structure and I want to find a value of token which is a sub-item of access_tokens for a comparing value of tokens. How can I find a token?
{
"_id" : ObjectId("5aa28846de35244ec439a563"),
"user" : ObjectId("5a9d53e52d989d2accda2ee5"),
"refresh_token" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJyZWZyZXNoX3Rva2VuIiwianRpIjoiNWE1NDZmOGQtNjBjMy00YmYzLTk0OGQtYjJiM2E5MDU5MWMwIiwib2JqZWN0aWQiOiI1YTlkNTNlNTJkOTg5ZDJhY2NkYTJlZTUiLCJleHAiOjE1MjA2MDQ3MjMsImlzcyI6IlByb25ldCBBUyIsImF1ZCI6IkF1dGhBcGkifQ.sxfUJgFnfMKKtSOLzksfPB-FqQN4ydaKi9YAVZqobK4",
"expTime" : "9.03.2018 14:12:03",
"access_tokens" : [{
"token" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhY2Nlc3NfdG9rZW4iLCJqdGkiOiIxMzM1Nzg0My0xNzRhLTQwOWYtOTgyMS0yY2ZhN2U1NmE5NDYiLCJvYmplY3RpZCI6IjVhOWQ1M2U1MmQ5ODlkMmFjY2RhMmVlNSIsImV4cCI6MTUyMDYwNDcyMywiaXNzIjoiUHJvbmV0IEFTIiwiYXVkIjoiQXV0aEFwaSJ9.KgYWj8w89W4DsyX5pkg7OPuCyT2DFUSAktkMmlb1kOk",
"exp_date" : "9.03.2018 14:12:03"
}]
}
I have class for my access token which is called SubToken and there is a structure for a collection which stored in mongodb and it is called TokenCollection. I reached subtoken (access token) which is sub item of a refresh token it is called Token.
SubToken res = TokenCollection.Find(new BsonDocument { { "access_tokens.token", access_token } }).FirstAsync().Result.access_tokens.Find(x => x.token == access_token);

I want to add custom tag defined in docisign on my document through REST API call in Apex

I want to add AccountName custom tag defined in docusign on my document through REST API call in Apex. Here is my REST API request body
{
"status" : "sent",
"customFields" : {
"textCustomFields" : [ {
"name" : "AccountName",
"show" : "true",
"required" : "False",
"value" : "Test Account",
"customFieldType" : "text"
} ]
}
}
The URL is https://demo.docusign.net/restapi/v2/accounts/'accountId'/envelopes
I use anchor string /txtAccountName1/ which I have added on my document but it does not map to any value of the custom field AccountName related to salesforce object. For the tabs it works fine it successfully maps the signer tag to s1 and date to the d1 but for this custom field it does not map the AccountName custom tag to the anchor string /txtAccountName1/. I have created the custom tag AccountName related to salesforce object and used anchor string as /txtAccountName{r}/. I am writing the code in sandbox and using Docusign Demo Account for the integration.I am not sure about the name used in textCustomField and value I used is the reason for not getting the required result. Though the Rest API request is returning the sucess.
How can I map the AccountName value to the anchorString defined in my document?
You are mixing two things customtab and customfields. CustomFields is the metadata on an envelope, there is no tab for this and you can send text type of list type custom fields, these type of fields are not visible to a signer/recipient and is sent as metadata in an envelope, For details related to CustomFields are available at https://docs.docusign.com/esign/restapi/Envelopes/EnvelopeCustomFields/create/
Now customTab, if you have already defined an account level customTab as "AccountName" then you can add them using REST API using below call like:
{
"textTabs": [{
"tabLabel": "AccountName",
"documentId": "83644555",
"recipientId": "84066562",
"pageNumber": 1,
"value": "AccountName",
"anchorString": "/txtAccountName1/"
}]
}
So before using the Accountlevel custom tab, you need to create it in your DocuSign account from webapp or using API - https://docs.docusign.com/esign/restapi/CustomTabs/CustomTabs/create/, Once it is created then only you can use it in an envelope.
As far as I can tell, you can't pull in the custom tag definition. You need to define the entire tag every time you use it, which means you'll need to use something like this:
"textCustomFields" : [ {
"name" : "AccountName",
"show" : "true",
"required" : "False",
"value" : "Test Account",
"anchorString": "/txtAccountName1/"
"customFieldType" : "text"
} ]

Suitescript 2.0 setting coupons and partner codes

We created a suitescript 2.0 script in our netsuite environment. We are using RESTlet to access it.
Our script creates a sales order with various fields. It works fine but we are unable to set a coupon code value or a partner code, we get the same error for both. We are using Internal ID and we tried coupon code itself as well.
Any idea?
Error:
{
"type":"error.SuiteScriptError",
"name":"INVALID_FLD_VALUE",
"message":"You have entered an Invalid Field Value 18 for the following field: couponcode",
"stack":[
"<anonymous>(N/record/recordService.js)",
"setSalesOrderData(adhoc$-1$debugger.user:71)",
"saveSaleOrder(adhoc$-1$debugger.user:17)",
"<anonymous>(adhoc$-1$debugger.user:107)",
"<anonymous>(adhoc$-1$debugger.user:6)"
],
"cause":{
"type":"internal error",
"code":"INVALID_FLD_VALUE",
"details":"You have entered an Invalid Field Value 18 for the following field: couponcode",
"userEvent":null,
"stackTrace":[
"<anonymous>(N/record/recordService.js)",
"setSalesOrderData(adhoc$-1$debugger.user:71)",
"saveSaleOrder(adhoc$-1$debugger.user:17)",
"<anonymous>(adhoc$-1$debugger.user:107)",
"<anonymous>(adhoc$-1$debugger.user:6)"
],
"notifyOff":false},"id":"","notifyOff":false
}
}
RESTlet code:
var objRecord = record.create({
type: record.Type.SALES_ORDER,
isDynamic: true
});
/* add other values.....*/
objRecord.setValue({ fieldId: 'couponcode', value: 538 });
var recordId = objRecord.save({
enableSourcing: false,
ignoreMandatoryFields: false
});
Are these coupon codes you are trying to set One-Time Use codes? Or are they linked to a Promotion?
Which internal ID are you using in the couponcode field?
Can you share the relevant parts of your RESTlet code as well?
I tested the following in the console (i.e. a Client Script) on a Sales Order, and it seems to set a Promotion and Coupon Code appropriately:
require(["N/currentRecord"], function(c) {
c.get().setValue({
"fieldId": "couponcode",
"value": 1
});
});
where 1 is the internal ID of the Promotion. If I use an internal ID not associated to a Promotion, I get no error, but nothing is populated in either field.
we finally got working code from Netsuite support, since there is such little help on this topic online, I am sharing it here. We grabbed what we needed into our own script, but this basic one works as well,
From netsuite support agent:
I created a simple SuiteScript 2.0 code for entering the values into Partner field (id: 'partner') and Coupon Code (id: 'couponcode'). Both fields are dropdown fields not multiselect fields.
The field Coupon Code depends on Promotion field that's why we should enter value in 'promocode' field instead of 'couponcode'.
/**
*#NApiVersion 2.x
*#NScriptType usereventscript
*/
define(['N/record'],
function(record) {
function AfterSubmit(context) {
var result = record.load({
type: 'salesorder',
id: 71040,
isDynamic: true
});
result.setValue ({
fieldId : 'partner',
value : 45140
});
result.setValue ({
fieldId : 'couponcode',
value : 'AMARILLO16'
});
result.save({
enableSourcing : false,
ignoreMandatoryFields : true
});
return true;
}
return {
afterSubmit: AfterSubmit
};
});
We had to do one modification for it to work for us:
result.setValue ({
fieldId : 'partner',
value : 45140
});
result.setText ({
fieldId : 'couponcode',
text : 'AMARILLO16'
});
result.save({
enableSourcing : false,
ignoreMandatoryFields : true
});

API Versioning in SailsJS

Based on this issue, I have nested controllers and blueprints are disabled. My issue is something like
api/Controllers :
v1/UserController.js
routes.js
'POST /v1/user/register': 'v1/UserController.createUser'
Policies.js
'v1/UserController': {
'*': [ 'passport'],
createUser: ['ModelPolicy','AuditPolicy','reqBodyValidation']
If it is nested controller: while accessing the endpoint :
Output is something :
error: Sending 500 ("Server Error") response:
Error: Invalid route option, "model".
I don't know about any models named: `v1/user`
Appreciate to resolve.
We actually did this in our project, and you can actually do this if you specify a string literal as the key for the controller in the JSON object like so:
'v1/UserController' : {
'*': [ 'passport'],
createUser: ['ModelPolicy','AuditPolicy','reqBodyValidation']
}

/me/apprequests returns null "from" property

When I use Graph API to access user's apprequests, /me/apprequests sometimes returns null "from" property, like the following.
{
"data" : [
{
"id" : "xxxxxx_xxxxx",
"to" : {
"name":"xxxxx xxxxx",
"id":"xxxxxx",
},
"from" : null
}
]
}
This occurs for some users data, but not always. How come this happens? All apprequests are created in same way, using Fb.ui({method: 'apprequests',...});
I've created a bug report and received an answer as follows.
It's due to privacy checks on the user who sent the request, in some
cases (user deactivated their account, user removed your app, etc) you
won't be able to read anything, including ID, about the sender of the
request.
http://developers.facebook.com/bugs/337541152923169?browse=search_4f0ad280300830331054933