Iteration within Azure AD B2C custom policy - azure-ad-b2c

Is there a way within a B2C custom policy to perform an iteration on some Json returned from a REST call.
Example:
If the REST service returned:
[
{
name: "item1",
value: "value1"
},
{
name: "item2",
value: "value2"
},
{
name: "item3",
value: "value3"
}
]
I want to be able to iterate through this array, and perform a calculation, and set a claim boolean if a record is found.
calculation(name, value) == calculation(another_input_claim, value)
I cannot use another REST service, as the specifics of the calculation need to be securely performed inside the B2C policy.
I can change the Json format of the input array if this helps?
Do you have any suggestions on implementing this within a B2C policy?

One of the options available here in B2C which I feel can be used is "GetClaimsFromJsonArray" This does help in extracting the values from the JSON Array.

Related

Azure Maps API - Search for location based on ID

I am working with the Azure Maps API, which returns information for a "fuzzy" match in this format:
{
type: 'Geography',
id: 'US/GEO/p0/52503',
score: 2.7559998035,
entityType: 'PostalCodeArea',
address: {
municipalitySubdivision: 'Brentwood',
municipality: 'Washington',
countrySecondarySubdivision: 'District of Columbia',
countrySubdivision: 'DC',
countrySubdivisionName: 'District of Columbia',
postalCode: '56967',
postalName: 'Parcel Return Service',
countryCode: 'US',
country: 'United States',
countryCodeISO3: 'USA',
freeformAddress: 'Parcel Return Service, DC 56967'
},
position: { lat: 38.91752, lon: -76.99356 },
viewport: { topLeftPoint: [Object], btmRightPoint: [Object] }
}
I want to be able to store the id property in a database (US/GEO/p0/52503 in this case) and then be able to get all the information from Azure without needing to basically duplicate the Azure data. I couldn't find any information in the Azure Maps API documentation about how to do a lookup for a location based on this ID - is this possible?
The is no way to retrieve results by ID in Azure Maps. Additionally, there is no guarantee that the ID will not change in the future (the V2 geocoding service doesn't have the ID). I believe it is mainly there for debugging purposes.
Storing the Address and optionally the lat/lon values in your database is likely the best option. Note that as long as you have an Azure subscription and your database is in Azure, you can store the lat/lon result data in your database (even if you aren't using Azure Maps anymore).

Apollo nodejs server; How to get query argument in when writing a plugin?

My objective is to write an Apollo plugin, that can save a specific input type on my context, for all queries.
The input is called "QueryOptions".
input QueryOptions {
tenant: ID
}
# example query
somePath(queryOptions: {
tenant: "some-tenant"
})
#example query 2
someOtherPath(queryOptions: {
tenant: "some-tenant"
})
Would it be able to determine the value of tenant, in an Apollo plugin? Maybe in the didResolveOperation hook?
Thanks for your input - currently I solve the issue by setting the tenant property on the context as the first thing on my resolvers.

Stripe - SubscriptionSchedule with 3DS

I am new with Stripe API and I want to create a Subscription per month with letting the possibility to enter a discount code if they want to.
For that, I use Subscription Schedule which allows me to create 2 phases inside. The first one would be, for example, the first week for 1€ and then the regular subscription.
Everything works well and I'm able to create the Subscription Schedule:
{
canceled_at: null
completed_at: null
created: 1602415626
current_phase: {end_date: 1602502026, start_date: 1602415626}
customer: "cus_IAzNj2kr9i1nw8"
default_settings: {billing_cycle_anchor: "automatic", billing_thresholds: null,
collection_method: "charge_automatically", default_payment_method: null, default_source: null,
…}
end_behavior: "release"
id: "sub_sched_1Hb2hiLShhG4xDx2Fw5Xn3mg"
livemode: false
metadata: {user_id: "263175", promo_code: "", sub_id_id: "11"}
object: "subscription_schedule"
phases: (2) [{…}, {…}]
released_at: null
released_subscription: null
renewal_interval: null
status: "active",
subscription: "sub_IBPWnRqS6gVVlm"
}
The only issue I'm facing is how to validate my user's cards with Subscription Schedule? When you create a regular Subscription you can have access to either pending_setup_intent or last_invoice.payment_intent, from which you can either ask 3DS or send an error message.
Can you guys tell me how I can achieve that?
Thank you
You'd need to retrieve the Subscription by its ID to get those, but then you should have access to them.

Cannot change workitem's parent through the azure devops api

I'm trying to programatically change a workitem's parent using the azure devops api but it's not working as expected.
I tried using update link endpoint and also remove link endpoint but none of them seem to be the correct one given that there is no way I can get a relation ID for the parent-child relationship to use in the request path.
The "relation ID" to send in path: is just the index of the relation being changed or removed in the WorkItemRelation[] on the Work Item being PATCHed.
Use the $expand=Relations argument in the query string of the GET operation for the work item whose parentage you want to change (Get Work Item).
https://dev.azure.com/{YOUR_ORG}/{YOUR_PROJ}/_apis/wit/workitems/{Child_ID}?$expand=Relations&api-version=5.0-preview.2
note: I'm not exactly sure, but I think the {YOUR_PROJ} value can be omitted.
With the resulting workitem object, get the index of the relation where the relation type is Hierarchy-Reverse, and use this as the leaf of the "path": "/relations/{index}" property sent in the PATCH body with op: "remove".
Get response (abbreviated):
{
"rel": "System.LinkTypes.Hierarchy-Reverse",
"url": "https://dev.azure.com/{YOUR_ORG}/_apis/wit/workItems/{Parent_ID}",
"attributes": {
"isLocked": false
}
}
Patch request (body):
[
{
"op": "test",
"path": "/rev",
"value": 1
},
{
"op": "remove",
"path": "/relations/0"
}
]
The examples in the documentation tend to perform a test on the revision of the work item before executing the remove or add operation. This isn't necessary, but it's probably a good idea.

Is there a best practice in apiary blueprint to specify field length (size) / format?

If using MSON, the only way I see to currently include field length would be to include as part of the description. Are there any plans to add support for this or are there any best practices (workarounds) being used for this purpose?
as an example, in the below MSON description, how could I specify that the tokenType max length is say 20 chars? (contrived example)
## accessToken
+ tokenType: `Bearer` (string) - The type of access token that was issued. Currently only 'Bearer' tokens are supported.
+ expiresIn: `1000` (number) - How much time in seconds until the token expires.
+ accessToken: `0.AQAAAVF-mqsiAAAAAAAbd0A71bIG8IUwcgHV7mAYiG7J.EAAQsWDnpqRj7WwyFVLTsdo0yXWh9L4` (string) - The access token to pass in the API call to access the protected resource.
MSON doesn't support specifying validation options such as a maximum length at the moment. The API Blueprint team have been exploring adding these features but this is still open for discussion on the best way to support this. There could be lots of validations so it's definitely a large topic to cover so we will need to find a clear way to express validations, which offers future support for declaring so this can evolve.
There is an open discussion on https://github.com/apiaryio/mson/issues/43 on the topic. If you have any ideas or syntax proposals they would be greatly appreciated.
Currently, you can provide a custom JSON Schema which specifies your validation options. As an example, you can achieve this validation using the following API Blueprint:
+ Response 200 (application/json)
+ Attributes
+ tokenType: Bearer (fixed) - The type of access token that was issued.
+ expiresIn: 1000 (number) - How much time in seconds until the token expires.
+ accessToken: `0.AQAAAVF-mqsiAAAAAAAbd0A71bIG8IUwcgHV7mAYiG7J.EAAQsWDnpqRj7WwyFVLTsdo0yXWh9L4` (string) - The access token to pass in the API call to access the protected resource.
+ Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"tokenType": {
"type": "string",
"enum": [
"Bearer"
]
},
"expiresIn": {
"type": "number"
},
"accessToken": {
"type": "string",
"maxLength": 20
}
},
"required": [
"tokenType"
]
}
I agree, this solution isn't great since you will need to duplicate some information in your MSON attributes and the schema itself. It would be far more idea to be able to specify the validation directly in MSON.
Just wanted to mention, you can use fixed for tokenType to indicate it has a fixed value which does not change. You could also used enum in the future to allow for multiple tokenType options.

Resources