[Solved] HTTP/1.0 400 Bad Request in get_access_token

Hi
I installed and prepared Gcal3 exactly as in your documentation. But now then I’m moving device in Armed state, error 400 appears
Exact text:
token error code: HTTP/1.0 400 Bad Request
Fatal Calendar Error

Found this text in GCal3.lua and added some debug info. So there is log output:
50 01/16/19 20:10:35.775 luup_log:83: GCal3 device: 8383 - Checking for access-token <0x7624f520>
50 01/16/19 20:10:35.775 luup_log:83: GCal3 device: 8383 - local function: get_access_token <0x7624f520>
50 01/16/19 20:10:35.776 luup_log:83: GCal3 device: 8383 - Getting a new token <0x7624f520>
50 01/16/19 20:10:35.776 luup_log:83: GCal3 device: 8383 - local function: os_command <0x7624f520>
50 01/16/19 20:10:35.777 luup_log:83: GCal3 device: 8383 - Command was: echo -n ‘{“iss":"gcal3-for-friday@gcal3-228616.iam.gserviceaccount.com”,“scope”:“https://www.googleapis.com/auth/calendar",“aud”:“https://accounts.google.com/o/oauth2/token”,"exp”:1547662235, “iat”:1547658635}’ | openssl base64 -e <0x7624f520>
50 01/16/19 20:10:35.799 luup_log:83: GCal3 device: 8383 - local function: os_command <0x7624f520>
50 01/16/19 20:10:35.800 luup_log:83: GCal3 device: 8383 - Command was: echo -n hidden | openssl dgst -sha256 -sign /etc/cmh-ludl/GCal3/GCal3cred.pem | openssl base64 -e <0x7624f520>
50 01/16/19 20:10:35.830 luup_log:83: GCal3 device: 8383 - post request for token: grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=hidden <0x7624f520> ← log added by me
50 01/16/19 20:10:35.999 luup_log:83: GCal3 device: 8383 - https token code: 400 <0x7624f520>
50 01/16/19 20:10:36.000 luup_log:83: GCal3 device: 8383 - https token status: HTTP/1.0 400 Bad Request <0x7624f520>
50 01/16/19 20:10:36.000 luup_log:83: GCal3 device: 8383 - token error code: HTTP/1.0 400 Bad Request <0x7624f520>
06 01/16/19 20:10:36.001 Device_Variable::m_szValue_set device: 83 service: urn:srs-com:serviceId:GCalIII variable: e[35;1mgc_NextEvente[0m was: CalendarID is set now: token error code: HTTP/1.0 400 Bad Request #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x7624f520>
06 01/16/19 20:10:36.003 Device_Variable::m_szValue_set device: 83 service: urn:srs-com:serviceId:GCalIII variable: e[35;1mgc_NextEventTimee[0m was: Credentials File Set now: #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x7624f520>
50 01/16/19 20:10:36.004 luup_log:83: GCal3 device: 8383 - GC.access_token is: false <0x7624f520>
50 01/16/19 20:10:36.005 luup_log:83: GCal3 device: 8383 - GCV.CredentialCheck is false <0x7624f520>

May be also helpful:
When I execute same request in Postman I get

{ "error": "unsupported_grant_type", "error_description": "Invalid grant_type: " }

What I’m doing wrong??

Codes in the 400 group generally mean that there is something like a calendar ID /credentials mismatch (i.e. right calendar wrong credentials file or vice-versa) or your settings in the calendar permissions are incorrect.

This code is very stable - so absent a network / connectivity issue with google, you should recheck your settings and the accuracy with which you created the credential file.

First, just in case something crazy is happening, use the test calendar ID and test credentials to eliminate all else.

Hi
Thank you for your answer

use the test calendar ID and test credentials to eliminate all else.

Result is the same: error 400

50 01/18/19 11:18:33.156 luup_log:83: GCal3 device: 838383 - ************** ARMED STATUS : 1 ***************** <0x75731520>
50 01/18/19 11:18:33.157 luup_log:83: GCal3 device: 838383 - local function: checkGCal <0x75731520>
50 01/18/19 11:18:33.157 luup_log:83: GCal3 device: 838383 - local function: getStartMinMax <0x75731520>
50 01/18/19 11:18:33.160 luup_log:83: GCal3 device: 838383 - StartMin is 2019-01-17T20:55:00Z StartMax is 2019-01-19T00:00:00Z <0x75731520>
50 01/18/19 11:18:33.161 luup_log:83: GCal3 device: 838383 - End of day is 2019-01-19T00:00:00 <0x75731520>
50 01/18/19 11:18:33.161 luup_log:83: GCal3 device: 838383 - local function: requestCalendar <0x75731520>
50 01/18/19 11:18:33.162 luup_log:83: GCal3 device: 838383 - local function: get_access_token <0x75731520>
50 01/18/19 11:18:33.162 luup_log:83: GCal3 device: 838383 - Getting a new token <0x75731520>
50 01/18/19 11:18:33.163 luup_log:83: GCal3 device: 838383 - local function: os_command <0x75731520>
50 01/18/19 11:18:33.164 luup_log:83: GCal3 device: 838383 - Command was: echo -n ‘{“iss":"gcaltest@gcal-test-1203.iam.gserviceaccount.com”,“scope”:“https://www.googleapis.com/auth/calendar",“aud”:“https://accounts.google.com/o/oauth2/token”,"exp”:1547803113, “iat”:1547799513}’ | openssl base64 -e <0x75731520>
50 01/18/19 11:18:33.185 luup_log:83: GCal3 device: 838383 - local function: os_command <0x75731520>
50 01/18/19 11:18:33.186 luup_log:83: GCal3 device: 838383 - Command was: echo -n hidden. | openssl dgst -sha256 -sign /etc/cmh-ludl/GCal3/GCal3Test.pem | openssl base64 -e <0x75731520>
50 01/18/19 11:18:33.216 luup_log:83: GCal3 device: 838383 - post request for token: grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=hidden <0x75731520>
50 01/18/19 11:18:33.389 luup_log:83: GCal3 device: 838383 - https token code: 400 <0x75731520>
50 01/18/19 11:18:33.390 luup_log:83: GCal3 device: 838383 - https token status: HTTP/1.0 400 Bad Request <0x75731520>
50 01/18/19 11:18:33.390 luup_log:83: GCal3 device: 838383 - token error code: HTTP/1.0 400 Bad Request <0x75731520>

I also noticed that jwt is the same either with your credential oor mine

I also noticed that jwt is the same either with your credential oor mine
... and almost the same as jwt1 in your code ))

-- jwt1 is base 64 encoded form of {"alg":"RS256","typ":"JWT"} local jwt1 = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9'

Call of openssl only adds point at the end of string.
So the problem is with openssl?

[quote=“KovVlad, post:4, topic:200452”]

I also noticed that jwt is the same either with your credential oor mine

… and almost the same as jwt1 in your code ))

-- jwt1 is base 64 encoded form of {"alg":"RS256","typ":"JWT"} local jwt1 = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9'

Call of openssl only adds point at the end of string.
So the problem is with openssl?[/quote]

What version of vera are you using and what version of openssl.

I’ve never seen this problem before - so something has changed / is different than expected :frowning:

Solved by openssl’s re-install

First it isn’t working

root@MiOS_45003051:~# openssl version Segmentation fault

After remove and install plugin works fine.
Thanks a lot