I think the gist of it is your authorization header isn’t right, but the error is less the clear…
To debug this, you should ensure that base64_encode("CLIENT_ID:CLIENT_SECRET") results in Q0xJRU5UX0lEOkNMSUVOVF9TRUNSRVQ=. Which might be as simple as removing the , true on ngx.encode_base64.
Create a URL safe Base64 encoded string where the contents before encoding are your application’s client ID, followed by a :, followed by your application’s secret key (e.g. URL safe Base64(<client_id>:<secret_key>)).
not URL safe Base64(<client_id>:<secret_key>), the true just is Base64(<client_id>:<secret_key>)
In the end I don’t think it really matters if it was URL safe or not given, in my limiting testing, doesn’t ever include those chars anyway. The crux of the problem in your case was the lack of padding.