Based on this article, https://auth0.com/docs/api/authentication#get-user-info, I am able get user info. The challenge is, instead of getting full user info, I am getting partial info.
I have "scope": "openid profile email" defined in my JWT. How can I retrieve full info? Am I missing something?
Code:
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://YOUR_DOMAIN/userinfo',
'headers': {
'Authorization': 'Bearer {TOKEN}',
'Cookie': 'COOKIE'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
Actual Response:
{
"email": "janedoe#exampleco.com",
"email_verified": true,
"name": "Jane Josephine Doe",
"nickname": "JJ",
"picture": "http://exampleco.com/janedoe/me.jpg",
"sub": "248289761001",
"updated_at": "1556845729"
}
Expected Response:
{
"address": {
"country": "us"
},
"birthdate": "1972-03-31",
"email": "janedoe#exampleco.com",
"email_verified": true,
"family_name": "Doe",
"gender": "female",
"given_name": "Jane",
"locale": "en-US",
"middle_name": "Josephine",
"name": "Jane Josephine Doe",
"nickname": "JJ",
"phone_number": "+1 (111) 222-3434",
"phone_number_verified": false,
"picture": "http://exampleco.com/janedoe/me.jpg",
"preferred_username": "j.doe",
"profile": "http://exampleco.com/janedoe",
"sub": "248289761001",
"updated_at": "1556845729",
"website": "http://exampleco.com",
"zoneinfo": "America/Los_Angeles"
}
You can create some Action and call them as you will get all user details inside function.
Login to Auth0 >>> leftside-menu-bar >>> Library >> Action
Related
I'm trying to use Klaviyo for the first time, and the natural starting point seems to be their new Node SDK. Unfortunately, their documentation seems to be an odd combination of extremely detailed, and laking any details.
I've set up my account and gotten my API key, but am failing to get a simple registration to succeed.
I thought I could do this:
import { ConfigWrapper, Profiles } from 'klaviyo-api';
import logger from '../utils/logger';
import requireEnvVariable from '../utils/requireEnvVariable';
export async function subscribe(profile) {
const apiKey = requireEnvVariable('KLAVIYO_PK');
ConfigWrapper(apiKey);
const user = Profiles.createProfile(profile)
.then(data => logger.debug({data}, 'Got profile data'))
.catch(error => {
logger.warn(error, 'Klaviyo error');
return error;
});
return true;
}
For profile, I'm passing in
{
"email": "me#example.com",
"phone_number": "",
"first_name": "Bob",
"last_name": "Smith"
}
but it responds with an error:
WARN: Klaviyo error
env: "development"
err: {
"type": "Error",
"message": "Bad Request",
"status": 400,
"response": {
"req": {
"method": "POST",
"url": "https://a.klaviyo.com/api/profiles/",
"data": {
"email": "me#example.com",
"phone_number": "",
"first_name": "Bob",
"last_name": "Smith"
},
"headers": {
"authorization": "Klaviyo-API-Key <my private key>",
"revision": "2022-10-17",
"user-agent": "klaviyo-api-node/1.0.2",
"content-type": "application/json",
"accept": "application/json"
}
},
"header": {
"date": "Wed, 28 Dec 2022 23:34:14 GMT",
"content-type": "application/vnd.api+json",
"content-length": "211",
"connection": "close",
"cf-ray": "780e1b056c3728f5-ORD",
"allow": "GET, POST, HEAD, OPTIONS",
"vary": "Cookie, Accept-Encoding",
"cf-cache-status": "DYNAMIC",
"cid": "UDiE82",
"ratelimit-limit": "700, 75;w=1, 700;w=60",
"ratelimit-remaining": "699",
"ratelimit-reset": "44",
"x-robots-tag": "noindex, nofollow",
"server": "cloudflare"
},
"status": 400,
"text": "{\"errors\":[{\"id\":\"5648779b-3e1a-4ccf-80c4-dc19b8b32a2c\",\"status\":400,\"code\":\"invalid\",\"title\":\"Invalid input.\",\"detail\":\"The payload provided in the request is invalid.\",\"source\":{\"pointer\":\"/data\"},\"meta\":{}}]}"
}
}
The various examples under Optional Parameters made me think that the above would Just Work; however, the docs also say, "For example values / data types, as well as whether parameters are required/optional, please reference the corresponding API Reference link," and "This SDK is a thin wrapper around our API. See our API Reference for full documentation on API behavior."
So looking at the Create Profile API Reference, I tried both
const user = Profiles.createProfile({attributes: profile})
and
const user = Profiles.createProfile({type: 'profile', attributes: profile})
but they both end up with the same error (except the reported data is updated appropriately, e.g.,
"status": 400,
"response": {
"req": {
"method": "POST",
"url": "https://a.klaviyo.com/api/profiles/",
"data": {
"type": "profile",
"attributes": {
"email": "me#example.com",
"phone_number": "",
"first_name": "Bob",
"last_name": "Smith"
}
},
What's the right way to use the new SDK? Or should I ignore this, and go back to creating manual fetch calls against their API?
Is it possible to create users in bulk via the REST API. Same as we do for single user in the below URL.
https://graph.windows.net/{MYADB2C}.onmicrosoft.com/users?api-version=1.6
We have the provision via the Azure portal but could'nt find anything with REST API.
UPDATED
Sample request for Batch processing
POST https://graph.windows.net/{}.onmicrosoft.com/$batch?api-version=1.6
Headers :
Authorization : {token}
Content-Type : multipart/mixed; boundary=changeset_***********
Body :
{
"requests": [
{
"id": "1",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"creationType": "LocalAccount",
"displayName": "test1#gamil.com",
"passwordPolicies": "DisablePasswordExpiration, DisableStrongPassword",
"passwordProfile": {
"password": "***",
"forceChangePasswordNextLogin": false
},
"signInNames": [
{
"type": "emailAddress",
"value": "test1#gamil.com"
}
]
},
"headers": {
"Content-Type": "application/json"
}
},
{
"id": "2",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"creationType": "LocalAccount",
"displayName": "test2#gmail.com",
"passwordPolicies": "DisablePasswordExpiration, DisableStrongPassword",
"passwordProfile": {
"password": "***",
"forceChangePasswordNextLogin": false
},
"signInNames": [
{
"type": "emailAddress",
"value": "test1#gamil.com"
}
]
},
"headers": {
"Content-Type": "application/json"
}
}
]
}
Yes. You can batch operations by referring to Batch processing | Graph API concepts.
But we recommend you use Microsoft Graph API JSON Batching instead of Azure AD Graph Batch processing because Azure AD Graph content is no longer updated.
An example using Microsoft Graph API here:
POST https://graph.microsoft.com/v1.0/$batch
Accept: application/json
Content-Type: application/json
{
"requests": [
{
"id": "1",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"displayName": "at1",
"mailNickname": "at1",
"userPrincipalName": "at1#**.onmicrosoft.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "password-value"
}
},
"headers": {
"Content-Type": "application/json"
}
},
{
"id": "2",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"displayName": "at2",
"mailNickname": "at2",
"userPrincipalName": "at2#**.onmicrosoft.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "password-value"
}
},
"headers": {
"Content-Type": "application/json"
}
},
{
"id": "3",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"displayName": "at3",
"mailNickname": "at3",
"userPrincipalName": "at3#**.onmicrosoft.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "password-value"
}
},
"headers": {
"Content-Type": "application/json"
}
}
]
}
You can have a quick test in Microsoft Graph Explorer.
curl - u user_name:password https://api.github.com/repos/:owner/:repo/commits/:ref
This returns...
{
"sha": sha,
"commit": {
"author": {
"name": name,
"email": "email",
"date": "2017-06-22T15:03:00Z"
},
"committer": {
"name": "name",
"email": "email",
"date": "timestamp"
},
"message": "message",
"tree": {
"sha": sha,
"url": url
},
"url": url,
"comment_count": 0
},
"url": url,
"html_url": html,
"comments_url": comments,
"author": {
"login": username,
"id": id,
"avatar_url": avatar,
"gravatar_id": "",
"url": url,
"html_url": html,
"followers_url": followers,
"following_url": following,
"gists_url": gists,
"starred_url": starred,
"subscriptions_url": subscriptions,
"organizations_url": organizations,
"repos_url": repos,
"events_url": events_url,
"received_events_url": events,
"type": "User",
"site_admin": false
},
"committer": {
"login": login,
"id": id,
"avatar_url": avatar,
"gravatar_id": "",
"url": url,
"html_url": html,
"followers_url": followers,
"following_url": following,
"gists_url": gists,
"starred_url": starred_url,
"subscriptions_url": subscription,
"organizations_url": orgs,
"repos_url": repos,
"events_url": events_url,
"received_events_url": events,
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": sha,
"url": url,
"html_url": html_url
}
],
"stats": {
"total": 2,
"additions": 1,
"deletions": 1
},
"files": [
{
"sha": sha,
"filename": file_name,
"status": "modified",
"additions": 1,
"deletions": 1,
"changes": 2,
"blob_url": blob_url,
"raw_url": raw_url,
"contents_url": contents_url,
"patch": the_data_i_need
}
]
}
The above gets me my desired output containing the payload.files.patch bit which I plan to parse for data to send to a db that will be the source for creating a visualization of my repo. Running this in postman also returns the desired output. However, when I run the following...
var options = {
url : 'https://api.github.com',
path : path,
method : 'GET',
headers : {'User-Agent':username, 'Authorization': 'Basic ' + new Buffer(username + ':' + password).toString('base64')},
}
request(options, function(err, res, body){
if(err){
console.log(err)
}
console.log(body)
})
It returns...
{"current_user_url":"https://api.github.com/user","current_user_authorizations_html_url":"https://github.com/settings/connections/applications{/client_id}","authorizations_url":"https://api.github.com/authorizations","code_search_url":"https://api.github.com/search/code?q={query}{&page,per_page,sort,order}","commit_search_url":"https://api.github.com/search/commits?q={query}{&page,per_page,sort,order}","emails_url":"https://api.github.com/user/emails","emojis_url":"https://api.github.com/emojis","events_url":"https://api.github.com/events","feeds_url":"https://api.github.com/feeds","followers_url":"https://api.github.com/user/followers","following_url":"https://api.github.com/user/following{/target}","gists_url":"https://api.github.com/gists{/gist_id}","hub_url":"https://api.github.com/hub","issue_search_url":"https://api.github.com/search/issues?q={query}{&page,per_page,sort,order}","issues_url":"https://api.github.com/issues","keys_url":"https://api.github.com/user/keys","notifications_url":"https://api.github.com/notifications","organization_repositories_url":"https://api.github.com/orgs/{org}/repos{?type,page,per_page,sort}","organization_url":"https://api.github.com/orgs/{org}","public_gists_url":"https://api.github.com/gists/public","rate_limit_url":"https://api.github.com/rate_limit","repository_url":"https://api.github.com/repos/{owner}/{repo}","repository_search_url":"https://api.github.com/search/repositories?q={query}{&page,per_page,sort,order}","current_user_repositories_url":"https://api.github.com/user/repos{?type,page,per_page,sort}","starred_url":"https://api.github.com/user/starred{/owner}{/repo}","starred_gists_url":"https://api.github.com/gists/starred","team_url":"https://api.github.com/teams","user_url":"https://api.github.com/users/{user}","user_organizations_url":"https://api.github.com/user/orgs","user_repositories_url":"https://api.github.com/users/{user}/repos{?type,page,per_page,sort}","user_search_url":"https://api.github.com/search/users?q={query}{&page,per_page,sort,order}"}
Which appears to be just generic request endpoints that likely are listed in their documentation. This leads me to believe that my app needs to be registered via the oauth process in order to request this information.
My current set up is I have an express.js app listening on an aws server for a github webhook. From that payload, i'm able to piece together the above requests.
However, I ran the above from my local machine using basic authentication. I also generated a token. I haven't run the node.js request code using the token, just username and password.
Do I need to change my authentication? Or do curl requests automatically chunk the results together while i would need to implicitly do that within my node.js code?
To use HTTP basic auth with request in node.js, you need to set a specific header:
var options = {
headers: {
'Authorization': 'Basic ' + new Buffer(username + ':' + password).toString('base64'),
/* some other headers... */
},
/* some other options... */
};
See this question for more details and examples
Are you sure about the path option?
I don't see anything in the request github documentation telling me that this is allowed.
I think you should put the full url in url,
like this
var options = {
url : 'https://api.github.com'+path,
method : 'GET',
headers : {'User-Agent':username, 'Authorization': 'Basic ' + new Buffer(username + ':' + password).toString('base64')},
}
request(options, function(err, res, body){
if(err){
console.log(err)
}
console.log(body)
})
The Amazon Cognito adminCreateUser documentation on TemporaryPassword states:
This parameter is not required. If you do not specify a value, Amazon
Cognito generates one for you.
How does the user ever get it? At first I thought it would get emailed to the user, but that doesn't seem to be the case. Then I thought maybe it would come back in the response. Nope.
Here's the code I'm calling in my node JS Lambda function:
adminCreateUser(
{
"UserPoolId": "us-east-1_XXXXXXXX",
"Username": "roger__mailinator.com",
"DesiredDeliveryMediums": [
"EMAIL"
],
"ForceAliasCreation": false,
"MessageAction": "SUPPRESS",
"UserAttributes": [
{
"Name": "given_name",
"Value": "Rodger"
},
{
"Name": "family_name",
"Value": "Ribbit"
},
{
"Name": "name",
"Value": "Rodger Ribbit"
},
{
"Name": "email",
"Value": "roger#mailinator.com"
},
{
"Name": "custom:title",
"Value": "Animation Designer"
},
{
"Name": "custom:company",
"Value": "76"
}
]
}, function(error, data) {
if (error) {
console.log("Error adding user to cognito: " + error, error.stack);
//...
} else {
console.log("Received back from cognito: " + JSON.stringify(data));
//...
}
});
and here's the response I get:
Received back from cognito:
{
"User": {
"Username": "roger__mailinator.com",
"Attributes": [
{
"Name": "custom:title",
"Value": "Animation Designer"
},
{
"Name": "sub",
"Value": "1cd612a0-0da0-4e7b-84c7-30570fab80a9"
},
{
"Name": "name",
"Value": "Rodger Ribbit"
},
{
"Name": "given_name",
"Value": "Rodger"
},
{
"Name": "family_name",
"Value": "Ribbit"
},
{
"Name": "email",
"Value": "roger#mailinator.com"
},
{
"Name": "custom:company",
"Value": "76"
}
],
"UserCreateDate": "2017-03-30T18:31:34.283Z",
"UserLastModifiedDate": "2017-03-30T18:31:34.283Z",
"Enabled": true,
"UserStatus": "FORCE_CHANGE_PASSWORD"
}
}
Where does the password go? Are we supposed to guess it? :-)
I think it's because you are passing "MessageAction": "SUPPRESS". That would suppress the sending of the email.
The temporary password is emailed to the user and he needs to reset it upon the first login.
The answer is that the user email needs to be verified before they'll receive it. So you need to modify the user attribute on email to be verified. See: https://stackoverflow.com/a/43033722/491553
I am trying to create a batch payout with a test sandbox account.
The 'create payment' function is working absolutely fine with correct response:
var paypal_sdk = require('paypal-rest-sdk');
var config_opts = {
'host': host, //host defined
'port':'',
'mode':'sandbox',
'client_id': client_id, //clientID defined
'client_secret': client_secret, //clientSecret defined
};
var makePayment = function (req, res, next) {
var create_payment_json = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://mystore.in",
"cancel_url": "http://mystore.in/contact"
},
"transactions": [
{
"amount": {
"currency": "USD",
"total": "1.00"
},
"description": "This is the payment description."
}
]
};
paypal_sdk.payment.create(create_payment_json,config_opts, function (err, data) {
if (err) console.log("ERRRRR", err);
console.log("Create Payment Response");
console.log(data);
//res.send('201');
});
}
makePayment(); //CALLING THE FUNCTION
But, when I am trying to create a new payout, by editing create_payment_json as:
var create_payment_json = {
"sender_batch_header": {
"email_subject": "You have a Payout!",
"recipient_type": "EMAIL"
},
"items": [
{
"recipient_type": "EMAIL",
"amount": {
"value": "1.0",
"currency": "USD"
},
"note": "Thanks for your patronage!",
"sender_item_id": "201403140001",
"receiver": "shirt-supplier-one#mail.com"
}
]
};
And main function as:
paypal_sdk.payout.create(create_payment_json,config_opts, function (err, data) {
if (err) console.log("ERRRRR", err);
console.log("Create Payment Response");
console.log(data);
//res.send('201');
});
I am receiving an error as follows:
{ [Error: Response Status : 401]
response:
{ error: 'invalid_client',
error_description: 'Client Authentication failed',
httpStatusCode: 401 },
httpStatusCode: 401 }
However, I am sure that credentials passed are correct and they are working perfectly in case of payment creation.
I am doing all this for the testing first. Also, the payout feature is enabled for this respective test paypal developer account.
Is there any possible solution?
I just got the solution. Well, to add, I must say paypal should provide proper error handling to let the developers know the reason behind each error.
The error was because of the currency that I had set in the configuration. The testing developer account was of some other country and the currency code was set as "USD".
Just make a new account and set currency code in config according to the country you had selected during the creation of that test developer account.
I test payout , as below code, it works fine. You can compare your code with my sample, you can add'sender_batch_id' parameter to have a try.
curl -v https://api.sandbox.paypal.com/v1/payments/payouts/ \
-H "Content-Type:application/json" \
-H "Authorization: *****" \
-d '{
"sender_batch_header": {
"sender_batch_id": "batch_25",
"email_subject": "You have a payment"
},
"items": [
{
"recipient_type": "EMAIL",
"amount": {
"value": 0.99,
"currency": "USD"
},
"receiver": "aaabbb#email.com",
"note": "Thank you.",
"sender_item_id": "item_1"
},
{
"recipient_type": "EMAIL",
"amount": {
"value": 0.90,
"currency": "USD"
},
"receiver": "bbbb#gmail.com",
"note": "Thank you.",
"sender_item_id": "item_2"
},
{
"recipient_type": "EMAIL",
"amount": {
"value": 2.00,
"currency": "USD"
},
"receiver": "cccc#gmail.com",
"note": "Thank you.",
"sender_item_id": "item_3"
}
]
}'