"detail": "CSRF Failed: CSRF token missing." - django

I was trying to test my API in DJango, but while trying to use a POST request to create a user, the following error shows up:
"detail": "CSRF Failed: CSRF token missing."
What should I do? Can I remove this? Or how should I pass the CSRF also in testing and in production? In theory, I put the false in CSRF_COOKIE_SECURE, so, I don't know what to do.

you have to add CSRF token to the request(and postman):
data: { csrfmiddlewaretoken: csrf_token, "username": "thesamething", "email": "thesamething", "password": "thesamething" }

Related

How to get value for Client_id and Client_Secret to call API from Postman

I am trying to call RingCentral API from Postman. This is my first attempt and so I am following what is provided by RingCentral documentation: https://developers.ringcentral.com/guide/messaging/sms/postman
I created a Sandbox account and an API app which uses following authorization:
However, when I call from the Postman, I am getting following error:
{
"error": "unauthorized_client",
"errors": [
{
"errorCode": "OAU-251",
"message": "Unauthorized for this grant type"
}
],
"error_description": "Unauthorized for this grant type"
}
Thank you.

Postman use Response of an Request for another Rwquest

So I have created an Collection with 2 Requests and many more can follow.
The first Request is an "Get Token" and I want to use the response access_token as my access token for my second Request.
The "Get Token" Request will be implemented in other Requests aswell.
Sadly I can't seem to find a ways implementing it.
This is my "Get Token" Request:
POST {{domain}}/oauth/token
Basic Auth
{
"client_id": "administration",
"grant_type": "password",
"scopes": "write",
"username": "{{user}}",
"password": "{{password}}"
}
And my second Request is an simple "Get Products" using this:
GET {{domain}}/product

error 403 Request had insufficient authentication scopes in postman

I'm trying to retrieve from Postman the answers of a form I created on google form but I can't do it.
First of all I created a form on google form.
I sent it to a person to get some answers.
I followed this tutorial which allowed me to set up oauth 2.0 on postman https://www.vulongtran.com/how-to-use-postman-with-google-cloud-platform-apis
Then as indicated in the api documentation of google form, I put in postman the GET method and I pass him the following url:
I replace obviously the formId by the id of my form which is the following 1FAIpQLSdNlmrvlMXvUlhSjiTb7YsqjHCTYZNRlJlGJnwkxyzNNSPe3A
This gives me the following url:
This gives me the following url:
https://forms.googleapis.com/v1/forms/1FAIpQLSdNlmrvlMXvUlhSjiTb7YsqjHCTYZNRlJlGJnwkxyzNNSPe3A/response
Before sending the request from postman I go on Postman->Authorization and I select the token set up thanks to the tutorial of this site:
https://www.vulongtran.com/how-to-use-postman-with-google-cloud-platform-apis
This does not work I get the following error:
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"status": "PERMISSION_DENIED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT",
"domain": "googleapis.com",
"metadata": {
"service": "forms.googleapis.com",
"method": "google.apps.forms.v1.FormsService.GetForm"
}
}
]
}
}
I am completely blocked if anyone can help me please?
Translated with www.DeepL.com/Translator (free version)

How to call Dialogflow Rest API with OAuth access token

I have created project in google console
Enable the Dialogflow API
Created OAuth v2 credential
Using this credentials i called access token api to generate token
https://accounts.google.com/o/oauth2/v2/auth?
scope=https://www.googleapis.com/auth/dialogflow&
access_type=offline&
include_granted_scopes=true&
response_type=code&
state=state_parameter_passthrough_value&
redirect_uri=http://localhost&
client_id= **i placed client id here**
I received access token and passed it to Dialog flow API
https://dialogflow.googleapis.com/v2/projects/**PROJECT-ID**/agent/sessions/123456:detectIntent
Header
Content-Type : application/json; charset=utf-8
Authorization : Bearer **ACCESS_TOKEN**
Body
{
"query_input": {
"text": {
"text": "I know french",
"language_code": "en-US"
}
}
}
Still i am getting this error
"error":{"code": 401, "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",…}
i am not able to identify where i went wrong
Please help thanks in advance
The code that i was passing in api was the OAuth Code(Thanks John Hanley)
API to generate Access token from OAuth Code
Post : https://oauth2.googleapis.com/token
Content-Type: application/x-www-form-urlencoded
{
"code":"OAuth Code",
"client_id":"Client ID",
"client_secret":"Client Secret",
"redirect_uri":"http://localhost",
"grant_type":"authorization_code"
}
In response you receive this
Response
{
"access_token": "Token",
"expires_in": 3599,
"refresh_token": "Refresh Token",
"scope": "https://www.googleapis.com/auth/dialogflow",
"token_type": "Bearer"
}
Pass this access token in header of google API

POST request from postman 4.2.2 to couchdb in localhost does not return cookie

I am sending a POST request to my local test_db (couchDB database):
POST http://localhost:1970/_session
using the following values in the body request:
x-www-form-urlencoded
name: admin
password: xxxxxx
the request executes correctly but in the response I do not get a cookie:
{
"ok": true,
"name": null,
"roles": [
"_admin",
"dbadmin"
]
}
do you know why?
Thank you for your help.
According to the documentation, the data returned is correct. The cookie is inside the response headers. Here's an example of how to retrieve it with PHP.