Work

curl --user 옵션을 사용했을 때 request

runicode 2022. 9. 21. 08:16

Authlib OAuth2 server 예제 ( https://docs.authlib.org/en/latest/flask/2/index.html ) 를 테스트 하며

curl -X POST --user "<client_id>:<client_secret>" 수행 시 request의 형태를 확인하고자 하였다.

authlib / example-oauth2-server 에 등록한 client info

C:\WINDOWS\system32>curl -v -u oTzkmwz4qQdK9iP7qQhDcZSJ:KR1q4Phw4kHPVXlUmUd5700qZiEhkZYXvMpKgxMKm5Fpj2GU -XPOST http://127.0.0.1:5000/oauth/token -F grant_type=client_credentials
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:5000...
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
* Server auth using Basic with user 'oTzkmwz4qQdK9iP7qQhDcZSJ'
> POST /oauth/token HTTP/1.1
> Host: 127.0.0.1:5000
> Authorization: Basic b1R6a213ejRxUWRLOWlQN3FRaERjWlNKOktSMXE0UGh3NGtIUFZYbFVtVWQ1NzAwcVppRWhrWllYdk1wS2d4TUttNUZwajJHVQ==
> User-Agent: curl/7.83.1
> Accept: */*
> Content-Length: 163
> Content-Type: multipart/form-data; boundary=------------------------843139e3d3fc9f8b
>
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: application/json
< Cache-Control: no-store
< Pragma: no-cache
< Content-Length: 108
< Server: Werkzeug/1.0.1 Python/3.8.3
< Date: Tue, 20 Sep 2022 22:51:38 GMT
<
{"access_token": "hAiwGKom8KNoejH13Hfgi2HQPQOmsVJIeyW8DPzEZ9", "expires_in": 864000, "token_type": "Bearer"}* Closing connection 0

C:\WINDOWS\system32>

 

--user "<client_id>:<client_secret>"base64로 인코딩되어 Authorization : Basic 과 함께 header에 적용됨을 확인하였으며

base64로 인코딩된 값을 구하기 위해 다음의 방법을 사용 할 수 있었다.

D:\workspace_oauth2>copy con credentials.txt
oTzkmwz4qQdK9iP7qQhDcZSJ:KR1q4Phw4kHPVXlUmUd5700qZiEhkZYXvMpKgxMKm5Fpj2GU^Z
        1개 파일이 복사되었습니다.

D:\workspace_oauth2>certutil -encode credentials.txt credentials.asc
입력 길이 = 73
출력 길이 = 160
CertUtil: -encode 명령이 성공적으로 완료되었습니다.

D:\workspace_oauth2>type credentials.asc
-----BEGIN CERTIFICATE-----
b1R6a213ejRxUWRLOWlQN3FRaERjWlNKOktSMXE0UGh3NGtIUFZYbFVtVWQ1NzAw
cVppRWhrWllYdk1wS2d4TUttNUZwajJHVQ==
-----END CERTIFICATE-----

D:\workspace_oauth2>

 

- ref : https://stackoverflow.com/questions/36292406/what-does-user-mean-with-curl