I have a google realtime API web application and I use the "realtime-client-utils.js" library to authenticate that is accessible at GitHub:
https://github.com/googledrive/realtime-utils.
When I call RealtimeUtils.authorize(onAuthComplete, usePopup)
I get a response object for the onAuthComplete callback method. This response object contains information about the authorization process:
But I need the email address of the google user that just authenticated himself. Can anybody tell me how I can get the email address?
I tried to use this tutorial:
https://developers.google.com/+/web/people/#retrieve-an-authenticated-users-email-address
You can try to use the People: get method to get a person's profile. Also, this method returns a person resource in the response body.
Here is the response that you can get by doing this.
{
"kind": "plus#person",
"etag": etag,
"nickname": string,
"occupation": string,
"skills": string,
"birthday": string,
"gender": string,
"emails": [
{
"value": string,
"type": string
}
],
"urls": [
{
"value": string,
"type": string,
"label": string
}
],
"objectType": string,
"id": string,
"displayName": string,
"name": {
"formatted": string,
"familyName": string,
"givenName": string,
"middleName": string,
"honorificPrefix": string,
"honorificSuffix": string
},
"tagline": string,
"braggingRights": string,
"aboutMe": string,
"relationshipStatus": string,
"url": string,
"image": {
"url": string,
},
"organizations": [
{
"name": string,
"department": string,
"title": string,
"type": string,
"startDate": string,
"endDate": string,
"location": string,
"description": string,
"primary": boolean
}
],
"placesLived": [
{
"value": string,
"primary": boolean
}
],
"isPlusUser": boolean,
"language": string,
"ageRange": {
"min": integer,
"max": integer
},
"plusOneCount": integer,
"circledByCount": integer,
"verified": boolean,
"cover": {
"layout": string,
"coverPhoto": {
"url": string,
"height": integer,
"width": integer
},
"coverInfo": {
"topImageOffset": integer,
"leftImageOffset": integer
}
},
"domain": string
}
For more information, check this SO question if it can help you.
There are a few ways to retrieve the user's email address. The easiest is to use the id_token returned on the user's access_token that you receive (#3 below).
1) You can use the UserInfo endpoint after including the 'profile' OAuth scope: https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=[token]. Making a dirty query to this API with your access token will return the user's email address.
2) As noted in a different answer, you can use the People.Get API.
3) (In my opinion the best option) Request and use the id_token (JWT) that can be returned along with a valid Google Access Token. For this you must include the 'https://www.googleapis.com/auth/userinfo.email' OAuth scope, and when making the call for Google Authorization, the 'response_type' param must be set to 'token id_token'. You can do this by editing the Realtime API to pass in 'response_type: "token id_token" along with the other params to gapi.auth.authorize.
Once you have your id_token, it needs to be decoded. You can use the code below and just pass in the response object that you receive. The resulting decoded id_token will contain the user's email address.
function decodeJWT(rawToken)
{
var decoded;
if (rawToken && rawToken.id_token)
{
var jwt = rawToken.id_token;
var parts = jwt.split('.');
try
{
decoded = JSON.parse(b64_to_utf8(parts[1]));
}
catch (err)
{
// Handle Error
}
}
return decoded;
}
function b64_to_utf8(str)
{
var utf8;
try
{
utf8 = decodeURIComponent(escape(window.atob(str)));
}
catch (err)
{
// Handle Error
}
return utf8;
}
Good luck!
Related
I have LogicApp which get HTTP Post from Azure Alerts.
I would like to create "DimensionNames" string variable, which includes all names in array.
DimensionNames value could be "name1,name2, name3, name4".
Finally I would use DimenstionNames string in "call Webhook".
How do it?
Request Body Json in "When a HTTP request is received"
{
"dimensions": {
"items": {
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"name",
"value"
],
"type": "object"
},
"type": "array"
}
}
Using variables and Join action you can convert array to a string variable. I have reproduced from my side and below are steps I followed,
Created an alert and configured a HTTP trigger logic app to it.
Designer of logic app will be,
The payload of http request is,
{
"dimensions": {
"items": {
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"name",
"value"
],
"type": "object"
},
"type": "array"
}
}
4. Next taken Initialize variable action as shown below,
Taken Join action to divide values from array with comma,
Next taken another initialize variable action to store value as a string,
In webhook action the value of string variable is used as body,
Outputs are shown below,
Http trigger:
Output of initialize variable,
Output if Join,
Output of initialize variable 2,
Reference link
I will try to explain my problem as best as possible for me.
I'm using Strapi as a backend and Nextjs as a frontend.
For the authentication I using NextAuth.
[...nextauth].js:
const options = {
providers: [
Providers.Credentials({
name: 'Credentials',
credentials: {
username: { label: "Email", type: "email", placeholder: "jsmith" },
password: { label: "Password", type: "password" }
},
authorize: async (credentials) => {
try {
const user = await axios.post(`${process.env.NEXT_PUBLIC_API_URL}/auth/local`, {
identifier: credentials.username,
password: credentials.password,
});
if (user.data) {
return user.data
} else {
return null
}
} catch (error) {
const errorMessage = error.response.data.message[0].messages[0].message
throw new Error(errorMessage)
}
}
}),
],
database: process.env.NEXT_PUBLIC_DATABASE_URL,
session: {
jwt: true,
},
callbacks: {
jwt: async (token, user) => {
if (user) {
token.jwt = user.jwt;
token.user = user.user;
}
return Promise.resolve(token);
},
session: async (session, token) => {
session.jwt = token.jwt;
session.user = token.user;
return Promise.resolve(session);
},
},
pages: {
signIn: '/login',
error: '/login'
},
};
const Auth = (req, res) =>
NextAuth(req, res, options);
export default Auth;
When I send form with identifier and password I getting session response with user data and jwt.
Everything working well, but if user objects have few more objects assigned to him, then something goes wrong and the session is empty.
Example:
I creating in Strapi simple collection with just two fields - image field, and owner (relation to user). Every response with image contents few lines:
"photo": {
"_id": "60ca03fa20bd43033a53950e",
"name": "Zrzut ekranu 2021-06-16 o 14.59.48.png",
"alternativeText": "",
"caption": "",
"hash": "Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b",
"ext": ".png",
"mime": "image/png",
"size": 170.69,
"width": 668,
"height": 636,
"url": "/uploads/Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b.png",
"formats": {
"thumbnail": {
"name": "thumbnail_Zrzut ekranu 2021-06-16 o 14.59.48.png",
"hash": "thumbnail_Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b",
"ext": ".png",
"mime": "image/png",
"width": 164,
"height": 156,
"size": 14.92,
"path": null,
"url": "/uploads/thumbnail_Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b.png"
},
"small": {
"name": "small_Zrzut ekranu 2021-06-16 o 14.59.48.png",
"hash": "small_Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b",
"ext": ".png",
"mime": "image/png",
"width": 500,
"height": 476,
"size": 121.79,
"path": null,
"url": "/uploads/small_Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b.png"
}
},
When I add 1 or 2 items with image and try to login to user who own that items then everything is fine, I can log in and receive full user object and jwt token.
But when I add 3 items there, session object is empty, and I can't log in. I do not receiving user object and jwt token.
With 3 items
With 2 items
When I using postman, even with 50 items response is good and include full user object and jwt token.
I think is because response is too large or something like that, but I have no clue how to deal with it.
I working on localhost (both - frontend and backend) on MacOS.
Is there anyone who can help me find a solution for that problem?
Kind Regards,
GP
The reason of above issue is that in api response is passed to many data, and next-auth store that all data in JWT, and JWT is stored in full in cookie, cookie is limited to 4096 bytes, and that simply brake that limit and response.
The simplest way to sort it out is to save only most important data in JWT.
You can do that in callback function.
I created a simple logic app triggered by sending a json payload and I need to retrieve a value of a property in order to use it in a condition scope.
Thanks for you help
Please use Parse Json action, please click Use sample payload to generate schema, and then paste your json to generate the schema needed to parse the json:
Then select the key of the value you want to get
===============update=============================
I defined a json string as input.
According to the json string you provided, the generated schema should look like this:
{
"properties": {
"CusttId": {
"type": "string"
},
"Direction": {
"type": "string"
},
"MyId": {
"type": "string"
},
"Reason": {
"type": "string"
},
"TestDateTime": {
"type": "string"
}
},
"type": "object"
}
I did a test and it can retrieve MyId:
I have to pass a JSON in the HTTP request and that JSON contains an array of addresses. Up until I add the array, the request is fine and I do get a response but as soon as I add the array of addresses, I get a bad request error
Below is my bad request
{
"searchType": "XXXXXX",
"searchCriteria": {
"firstName": "J",
"lastName": "S",
"birthYear": 1980,
"birthMonth": 1,
"birthDay": 1
"addresses":{
"address": [
{
"_city": "LOUISVILLE",
"_state": "TN",
"_zip": "37777-3917"
},
{
"_address1": "920 E LAMAR ALEXANDER PARKWAY",
"_city": "MARYVILLE",
"_state": "TN",
"_zip": "37804"
},
{
"_address1": "Last Reported Address - Out of State",
"_city": "LOUISVILLE",
"_state": "TN",
"_zip": "37777"
}
]
}
},
"identification": {
"ipAddress": "XXXXXXXX",
"applicationID": "XXXX"
}
}
Can someone please guide me how this can be achieved in Jmeter?
What you provide is not a valid JSON you can double check it using an online JSON validator
Since we don't have any idea regarding how the "good" request should look like we cannot come up with the 100% valid solution.
You can try to use the below JSON payload as the reference, it's syntactically correct but I don't guarantee your application will accept it:
{
"searchType": "XXXXXX",
"searchCriteria": {
"firstName": "J",
"lastName": "S",
"birthYear": 1980,
"birthMonth": 1,
"birthDay": {
"addresses": {
"address": [
{
"_city": "LOUISVILLE",
"_state": "TN",
"_zip": "37777-3917"
},
{
"_address1": "920 E LAMAR ALEXANDER PARKWAY",
"_city": "MARYVILLE",
"_state": "TN",
"_zip": "37804"
},
{
"_address1": "Last Reported Address - Out of State",
"_city": "LOUISVILLE",
"_state": "TN",
"_zip": "37777"
}
]
}
}
},
"identification": {
"ipAddress": "XXXXXXXX",
"applicationID": "XXXX"
}
}
I would recommend recording the request which is successful using JMeter's HTTP(S) Test Script Recorder and once you have a working request which you can successfully replay you can correlate dynamic and parameterize user-specific values.
I'm retrieving messages from my Gmail using Gmail API. specifically, the email with Hangouts conversations using this url: https://www.googleapis.com/gmail/v1/users/me/messages?q=in:chats
When I enter in a message, I see this structure
{
"id": "1555561f7b8e1sdf56b",
"threadId": "155552511dfsd83ce98",
"labelIds": [
"CHAT"
],
"snippet": "df",
"historyId": "270812",
"internalDate": "1466016331704",
"payload": {
"partId": "",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "From",
"value": "\"Oscar J. Irún\" <Oscarjiv91#gmail.com>"
}
],
"body": {
"size": 2,
"data": "ZGY="
}
},
"sizeEstimate": 100
}
as you can see, the body message is "df". Everything it's ok so far.
The problem comes when the Hangout message is an image. The snippet field is empty, and it doesnt show any attachment in the message. This is an example:
{
"id": "155558233274d78c91",
"threadId": "15fd5552511d83ce98",
"labelIds": [
"CHAT"
],
"snippet": "",
"historyId": "27sd0827",
"internalDate": "1466018445133",
"payload": {
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "From",
"value": "\"Oscar J. Irún\" <Oscarjiv91#gmail.com>"
}
],
"body": {
"size": 0,
"data": ""
}
},
"sizeEstimate": 100
}
I need to retrieve this inline images. Any help will be appreciated!
You can retrieve attachments by using Users.messages.attachments:get. Take note that this request requires authorization. All requests to the Gmail API must be authorized by an authenticated user. Gmail uses the OAuth 2.0 protocol for authenticating a Google account and authorizing access to user data.
HTTP request
GET https://www.googleapis.com/gmail/v1/users/userId/messages/messageId/attachments/id
public static void getAttachments(Gmail service, String userId, String messageId)
throws IOException {
Message message = service.users().messages().get(userId, messageId).execute();
List<MessagePart> parts = message.getPayload().getParts();
for (MessagePart part : parts) {
if (part.getFilename() != null && part.getFilename().length() > 0) {
String filename = part.getFilename();
String attId = part.getBody().getAttachmentId();
MessagePartBody attachPart = service.users().messages().attachment().
get(userId, messageId, attId).execute();
byte[] fileByteArray = Base64.decodeBase64(attachPart.getData());
FileOutputStream fileOutFile =
new FileOutputStream("directory_to_store_attachments" + filename);
fileOutFile.write(fileByteArray);
file OutFile.close();
}
}
}
JUST FYI for PHP the solution is something similar to this:
base64_decode(strtr($gmail->service->users_messages_attachments->get('me', $message->id, $arrPart['body']['attachmentId'])->data,'-_', '+/'));