REST authorization bearer token denied
After successfully receiving a bearer token, I still can't query the API. Any help with trouble shooting would be great. Here is my workflow in HTTP:
[code type="markup"]
#Request
POST https://192.168.1.10/_pxc_api/api/auth/auth-token
content-type: application/json
{
"scope":"variables"
}
#Response
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 08 Oct 2021 14:37:03 GMT
Content-Type: application/json
Content-Length: 44
Connection: close
Status: 200 OK
read_time: 2021-10-08T14:37:03.996969Z
end_time: 2021-10-08T14:37:03.997446Z
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
X-debug-message: location _pxc_api
{
"code": "XccK0YxVm4lyq3uv",
"expires_in": 600
}
[/code]
[code type="markup"]
#Request
POST https://192.168.1.10/_pxc_api/api/auth/access-token
content-type: application/json
{
"code": "XccK0YxVm4lyq3uv",
"grant_type": "authorization_code",
"username": "admin",
"password": "12345678"
}
#Response
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 08 Oct 2021 14:42:02 GMT
Content-Type: application/json
Content-Length: 84
Connection: close
Status: 200 OK
read_time: 2021-10-08T14:42:02.136994Z
Set-Cookie: acctkey=26e221af9fc7fc58; Path=/_pxc_api/api/auth/access-token; Secure; HttpOnly
end_time: 2021-10-08T14:42:02.167995Z
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
X-debug-message: location _pxc_api
{
"token_type": "Bearer",
"access_token": "22qSiGP7ZGp7u4jFATVK0jwiqDWOua79",
"roles": []
}
[/code]
[code type="markup"]
#Request
POST https://192.168.1.10/_pxc_api/api/variables
content-type: application/json
authorization: Bearer 22qSiGP7ZGp7u4jFATVK0jwiqDWOua79
{
"pathPrefix": "Arp.Plc.Eclr/",
"paths": "Y0_BellSOL"
}
#Response
HTTP/1.1 401 Unauthorized
Server: nginx
Date: Fri, 08 Oct 2021 14:45:22 GMT
Content-Type: application/json
Content-Length: 132
Connection: close
Status: 401 Unauthorized
WWW-Authenticate: Bearer realm="pxcapi", error="invalid_token"
X-debug-message: location _pxc_api
{
"apiVersion": "1.6.0.0",
"projectCRC": 2295408380,
"error": {
"code": 401,
"details": [
{
"domain": "authorization",
"reason": "accessDenied"
}
]
}
}
[/code]
[code type="markup"]
#Request
POST https://192.168.1.10/_pxc_api/api/auth/auth-token
content-type: application/json
{
"scope":"variables"
}
#Response
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 08 Oct 2021 14:37:03 GMT
Content-Type: application/json
Content-Length: 44
Connection: close
Status: 200 OK
read_time: 2021-10-08T14:37:03.996969Z
end_time: 2021-10-08T14:37:03.997446Z
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
X-debug-message: location _pxc_api
{
"code": "XccK0YxVm4lyq3uv",
"expires_in": 600
}
[/code]
[code type="markup"]
#Request
POST https://192.168.1.10/_pxc_api/api/auth/access-token
content-type: application/json
{
"code": "XccK0YxVm4lyq3uv",
"grant_type": "authorization_code",
"username": "admin",
"password": "12345678"
}
#Response
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 08 Oct 2021 14:42:02 GMT
Content-Type: application/json
Content-Length: 84
Connection: close
Status: 200 OK
read_time: 2021-10-08T14:42:02.136994Z
Set-Cookie: acctkey=26e221af9fc7fc58; Path=/_pxc_api/api/auth/access-token; Secure; HttpOnly
end_time: 2021-10-08T14:42:02.167995Z
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
X-debug-message: location _pxc_api
{
"token_type": "Bearer",
"access_token": "22qSiGP7ZGp7u4jFATVK0jwiqDWOua79",
"roles": []
}
[/code]
[code type="markup"]
#Request
POST https://192.168.1.10/_pxc_api/api/variables
content-type: application/json
authorization: Bearer 22qSiGP7ZGp7u4jFATVK0jwiqDWOua79
{
"pathPrefix": "Arp.Plc.Eclr/",
"paths": "Y0_BellSOL"
}
#Response
HTTP/1.1 401 Unauthorized
Server: nginx
Date: Fri, 08 Oct 2021 14:45:22 GMT
Content-Type: application/json
Content-Length: 132
Connection: close
Status: 401 Unauthorized
WWW-Authenticate: Bearer realm="pxcapi", error="invalid_token"
X-debug-message: location _pxc_api
{
"apiVersion": "1.6.0.0",
"projectCRC": 2295408380,
"error": {
"code": 401,
"details": [
{
"domain": "authorization",
"reason": "accessDenied"
}
]
}
}
[/code]
Comments
https://www.plcnext.help/te/Service_Components/REST_data_interface/REST_data_interface_Introduction.htm
Here is a trace from a session that successfully reads and writes GDS variables - hopefully there's some clues in there that might help with your problem.