I am new in Django and working on django-rest-social-auth.
I want to implement social login in my app.(frontend- angular, Backend- Django)
but I am not getting what is the code parameter below request.
POST /api/login/social/token/
input:
{
"provider": "facebook",
"code": "AQBPBBTjbdnehj51"
}
output:
{
"token": "68ded41d89f6a28da050f882998b2ea1decebbe0"
}
POST /api/login/social/token_user/
input:
{
"provider": "facebook",
"code": "AQBPBBTjbdnehj51"
}
output:
{
"username": "Alex",
"email": "user#email.com",
// other user data
"token": "68ded41d89f6a28da050f882998b2ea1decebbe0"
}
Related
I am using ReactJS on the frontend: I successfully retrieved the access token from Google's Oauth service, but it doesn't give me any profile information for the 'current user'.
I tried using the /userInfo endpoint, ?access_token={my_access_token} query str, and some other solutions but I keep getting weird errors.
Currently I have:
const { access_token, refresh_token } = res.data; // now I have valid access_token
let userInfo = await axios.get("https://www.googleapis.com/oauth2/v3/userinfo",
{
headers: {
Authorization: `Bearer ${access_token}`
}
}); // ERROR WHEN MAKING THIS CALL.
My specific 401 error is as follows:
If there are better ways of getting user info (such as first/last name, email, etc. some sort of unique ID) please let me know.
You shouldnt rely on the user info endpoint to get user profile informaiton. As long as you are requesting the profile scope from the user, or even email. you should go though the People api. This will give you access to all of the users profile data.
GET https://people.googleapis.com/v1/people/me?personFields=names HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
response
{
"resourceName": "people/117dd2004755326722775346",
"etag": "%EgUBAi43PRoEAQIFBddyIMR3BzQkR2cnI1ZGc9",
"names": [
{
"metadata": {
"primary": true,
"source": {
"type": "PROFILE",
"id": "117200155326727753146"
}
},
"displayName": "Linda Lawton",
"familyName": "Lawton",
"givenName": "Linda",
"displayNameLastFirst": "Lawton, Linda",
"unstructuredName": "Linda Lawton"
},
{
"metadata": {
"source": {
"type": "CONTACT",
"id": "3faa96eb0118baa4be"
}
},
"displayName": "Linda Lawton",
"familyName": "Lawton",
"givenName": "Linda",
"displayNameLastFirst": "Lawton, Linda",
"unstructuredName": "Linda Lawton"
}
]
}
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 referred to this documentation to make a POST request.
Below is the error while making a POST request to create a conditional access policy
{
"message": "There was an internal server error while processing the request. Error ID: 2dbb1530-4ce6-44f5-9c63-08de28d7218a",
"innerError": {
"request-id": "2dbb1530-4ce6-44f5-9c63-08de28d7218a"
}
}
Payload being passed with the request is below:
{
"displayName": "Test Policy",
"state": "enabled",
"conditions": {
"clientAppTypes": ["modern", "browser"],
"applications": {
"includeApplications": ["None"]
},
"users": {
"includeUsers": [
"08290005-23ba-46b4-a377-b381d651a2fb"
]
},
"locations": {
"includeLocations": ["All"],
"excludeLocations": ["AllTrusted"]
}
},
"grantControls": {
"operator": "OR",
"builtInControls": ["approvedApplication"]
}
}
I've tried using this endpoint to get a policy:
https://graph.microsoft.com/beta/{tenant_id}/conditionalAccess/policies
Which successfully returns an existing policy. However, the above POST request is not working.
The "approvedApplication" requirement only supports the iOS and Android for device platform condition. See details here.
You need to add "includePlatforms" iOS and android into the json body.
{
"displayName": "Test Policy",
"state": "enabled",
"conditions": {
"clientAppTypes": ["modern", "browser"],
"applications": {
"includeApplications": ["None"]
},
"users": {
"includeUsers": [
"08290005-23ba-46b4-a377-b381d651a2fb"
]
},
"platforms": {
"includePlatforms": [
"iOS", "android"
]
},
"locations": {
"includeLocations": ["All"],
"excludeLocations": ["AllTrusted"]
}
},
"grantControls": {
"operator": "OR",
"builtInControls": ["approvedApplication"]
}
}
When using the "Send To Messenger" plugin, the response received is:
{
"object": "page",
"entry": [
{
"id": "410441912660258",
"time": 1506529761355,
"messaging": [
{
"recipient": {
"id": "410441912660258"
},
"timestamp": 1506529761355,
"sender": {
"id": "1388094137927363"
},
"optin": {
"ref": "login"
}
}
]
}
]
}
However, when I interact with Messenger using the same Messenger Account, Facebook sends:
{
"originalRequest": {
"source": "facebook",
"data": {
"sender": {
"id": "1271682282961502"
},
"recipient": {
"id": "1818762375111057"
},
"message": {
"mid": "mid.$cAAZ2J6JWBDZk9XGKQVexCxoKu27Y",
"text": "hi",
"seq": 17289
},
"timestamp": 1506529788481
}
}
}
Note that, despite using the same Messenger account, the sender/recipient IDs are different. So I can't match any users up from the Messenger Chat vs the Send To Messenger button.
I believe this is because the "Send To Messenger" button is using the Page Scoped User ID of the relevant Facebook Page, instead of the Facebook App. Is there any way to match these two IDs or, to tell the Send To Messenger button to use the APP ID instead of the Page ID?
You can use the ID matching API
https://developers.facebook.com/docs/messenger-platform/identity/id-matching
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,'-_', '+/'));