(06-28-2024, 06:02 PM)kenjis Wrote: See https://github.com/codeigniter4/CodeIgni...t.php#L142
The request method has three parameters, $method, $url, and $options.
Code:
$response =$client->request('POST', $apiURL, ['auth' => [$client_id, $client_secret, 'basic'],'debug' => true]);
Now debug....
Code:
* Connected to dispatchapi-sandbox-qa.auth.eu-west-1.amazoncognito.com (54.78.173.212) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=*.auth.eu-west-1.amazoncognito.com
* start date: Dec 29 00:00:00 2023 * Connected to dispatchapi-sandbox-qa.auth.eu-west-1.amazoncognito.com (54.78.173.212) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=*.auth.eu-west-1.amazoncognito.com
* start date: Dec 29 00:00:00 2023 GMT
* expire date: Jan 26 23:59:59 2025 GMT
* subjectAltName: host "dispatchapi-sandbox-qa.auth.eu-west-1.amazoncognito.com" matched cert's "*.auth.eu-west-1.amazoncognito.com"
* issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M03
* SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Server auth using Basic with user 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
* Using Stream ID: 1 (easy handle 0x56e10afc57a0)
> POST /oauth2/token?grant_type=client_credentials HTTP/2
Host: dispatchapi-sandbox-qa.auth.eu-west-1.amazoncognito.com
authorization: Basic NjNvaGwzYWhyMjU5Z251YTk1NHRzcTg4OWU6Y29mcWFlOTg3bzUxNzd1c25tdGZlYnEyZ3I3bW00dmc2aGo2azVlanVqOXNnMHVuYWt0
accept: */*
content-length: 0
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 405
< date: Sun, 30 Jun 2024 07:31:47 GMT
< content-length: 0
< set-cookie: XSRF-TOKEN=182b2889-5ae7-42c8-8fdc-e5787365b6ed; Path=/; Secure; HttpOnly; SameSite=Lax
< x-amz-cognito-request-id: 3a337c8c-3151-4de7-886c-45d06d77339b
< x-content-type-options: nosniff
< x-xss-protection: 1; mode=block
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< pragma: no-cache
< expires: 0
< strict-transport-security: max-age=31536000 ; includeSubDomains
< x-frame-options: DENY
< server: Server
< allow: GET
* The requested URL returned error: 405
* stopped the pause stream!
* Connection #0 to host dispatchapi-sandbox-qa.auth.eu-west-1.amazoncognito.com left intactGMT
* expire date: Jan 26 23:59:59 2025 GMT
* subjectAltName: host "dispatchapi-sandbox-qa.auth.eu-west-1.amazoncognito.com" matched cert's "*.auth.eu-west-1.amazoncognito.com"
* issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M03
* SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Server auth using Basic with user 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
* Using Stream ID: 1 (easy handle 0x56e10afc57a0)
> POST /oauth2/token?grant_type=client_credentials HTTP/2
Host: dispatchapi-sandbox-qa.auth.eu-west-1.amazoncognito.com
authorization: Basic NjNvaGwzYWhyMjU5Z251YTk1NHRzcTg4OWU6Y29mcWFlOTg3bzUxNzd1c25tdGZlYnEyZ3I3bW00dmc2aGo2azVlanVqOXNnMHVuYWt0
accept: */*
content-length: 0
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 405
< date: Sun, 30 Jun 2024 07:31:47 GMT
< content-length: 0
< set-cookie: XSRF-TOKEN=182b2889-5ae7-42c8-8fdc-e5787365b6ed; Path=/; Secure; HttpOnly; SameSite=Lax
< x-amz-cognito-request-id: 3a337c8c-3151-4de7-886c-45d06d77339b
< x-content-type-options: nosniff
< x-xss-protection: 1; mode=block
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< pragma: no-cache
< expires: 0
< strict-transport-security: max-age=31536000 ; includeSubDomains
< x-frame-options: DENY
< server: Server
< allow: GET
* The requested URL returned error: 405
* stopped the pause stream!
* Connection #0 to host dispatchapi-sandbox-qa.auth.eu-west-1.amazoncognito.com left intact
it seem that accept only GET request but the api request a POST :
Code:
curl -X POST --user '<CLIENT_ID>:<CLIENT_SECRET>' -H 'Content-Type: application/x-www-form-urlencoded' 'https://dispatchapi-sandbox-qa.auth.eu-west-1.amazoncognito.com/oauth2/token?grant_type=client_credentials'