authlib / example-oauth2-server

Example for OAuth 2 Server for Authlib.
https://authlib.org/
684 stars 285 forks source link

Fail to get toke using encoded client credentials #88

Closed juhyun closed 2 years ago

juhyun commented 2 years ago

According to the authlib document, if user uses'client_secret_basic' client auth method, 'HTTP Basic Authorization' can be used. However, with 'HTTP basic Authorization' it failed to get token.

  1. Successfully getting token using "curl -u :" [root@server ~]# curl -u e7Ll5b67Xv5zZKZBuLLwoOWm:gkZICKnukGLDQmT0PMa1Yp2r11dKL7OmLjiKZFGwMPLRAGrn -XPOST http://127.0.0.1:5001/oauth/token -F grant_type=password -F username=opuser -F password=valid {"access_token": "MWptz8DVDYYfqYy6inSHq2phkvZZ6fyo8TgDEgEpKK", "expires_in": 864000, "refresh_token": "oQJpPhiTXi10AzfwNfoKQshvE4YosI86FMHY4ban5BzG7JI3", "token_type": "Bearer"}

  2. Failed to get token using "encoded client credentials" [root@server ~]# echo -n 'e7Ll5b67Xv5zZKZBuLLwoOWm:gkZICKnukGLDQmT0PMa1Yp2r11dKL7OmLjiKZFGwMPLRAGrn' | base64 c [root@server ~]# [root@server ~]# curl -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic ZTdMbDViNjdYdjV6WktaQnVMTHdvT1dtOmdrWklDS251a0dMRFFtVDBQTWExWXAycjExZEtMN09tTGppS1pGR3dNUExSQUdybg==" -XPOST http://127.0.0.1:5001/oauth/token -F grant_type=password -F username=opuser -F password=valid {"error": "invalid_grant"}

-----------Updated--------------- Oh, without using '-H "Content-Type: application/x-www-form-urlencoded"', http basic authentication works fine..