3👍
✅
Use single quotes around your last parameter:
curl -X POST -d "grant_type=password&username=admin&password=123" 'http://tygkDGuF.re@HmpJB!G=oi5pHtbgxW96I9w8iTd0:zFpyRXwgUKglYAs6b=v8UwlA3qqxZr!=hn3PgzQQ5CgO=OVR-O26reO;T8xcn;xcurcbC7kPr8r-York9TIEKKEM6EFRUOhR:oU!=S3A;QQ1pmAK8dNso48KfYNgYO_F@http://127.0.0.1:8080/o/token/'
If you don’t then the shell will interpret !
as an operator for recalling history. And ;
will be interpreted as command separators.
3👍
I used http://docs.python-requests.org/en/latest/:
response = requests.post(
'http://localhost:8000/o/token/',
data={
'grant_type': 'password',
'username': 'you',
'password': 'secret',
'client_id': 'WpDs.u9yrWD3js;fYq?cog;MvTiq0Bj02r8LTL_v',
'client_secret': 'c1W2:PzVsccsIt_G_uxnwE_TC08z14IKqYYKy0DJAok;_B?RvuVashIsARqhGwF=ChoBJveA7LvB;C?IeXyp?0ZiyBtg9;tSwTjVdC.K_f@n=K;@V;2:VoX@IhPyiHzC'
}
)
print(response.text)
- [Django]-Django all-auth Form errors not displaying
- [Django]-Django 2 upgrade lost filter_horizontal functionality
- [Django]-Execute background process from django that can't be interrupted by the web server
- [Django]-Include is not defined
2👍
I tried this:
curl -X POST -d "grant_type=password&username=name&password=123" 'http://wHMBrLRjQU_!;pYIPgLGurD2SIYH.9r19!h7JSds:wCQ?KHaoVb;aS:-sqCVkkNwrwGP3B?hD9yZTGY;zFCvbR5H8Fy=mh79KYFQBtIJWza380yFF!OHeb-HyFyGtSY54oUK;_qPF4nsaAI0mt_INr.JQ0vdUgAluWPI9EeDk@127.0.0.1:8000/o/token/'
curl: (6) Couldn't resolve host 'wHMBrLRjQU_!;pYIPgLGurD2SIYH.9r19!h7JSds'
I did everything on a manual (link)
- [Django]-How can I disable/remove authorize button in swagger drf_yasg (maintain CSRF) – django
- [Django]-IF statement not working with list difference
- [Django]-Cannot urlencode() after storing QueryDict in session
- [Django]-Insert pandas data frame into Postgres
1👍
In my case, below is work:
curl -X POST -d 'client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD' http://localhost:8000/o/token/
Note i used signs ‘*‘.
- [Django]-Django admin throws error after installing tastypie?
- [Django]-Django Heroku not serving static files when Debug=False
0👍
And a Javascript solution to get token from django-oauth-toolkit:
async function getToken () {
let res = await fetch("https://<your_domain>/o/token/", {
body: new URLSearchParams({
grant_type: 'password',
username: '<user_name>',
password: '<user_pass>',
client_id: '<client_app_id>',
client_secret: '<client_pass>'
}),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST"
})
return res.json();
}
console.log(await getToken());
Your client application authorisation grant type should be: “Resource owner password-based”
P.S. I’ve failed to get token via “Content-Type”: “application/json”, not sure why (django-oauth-toolkit documentation says nothing about that).
- [Django]-How to set default value in Django while filtering objects from models
- [Django]-Using django.setup() from a subdirectory, how to reference settings?
- [Django]-Is there an easy way reverse a template render?
- [Django]-Django app not found despite adding to INSTALLED_APPS?
- [Django]-Explicitly clear django memcached flush/cache() OR delete specific per-view-cache key
Source:stackexchange.com