Closed leggetter closed 7 years ago
FYI, my pem file predates the flag for the CLI to save the key to file. So my file will have been created by copy/pasting from the console into a file. I don't know if this makes any difference, but... maybe.
@leggetter Could you change the regex so that it has \\n?
at the end to catch a trailing newline, if there is one?
@judy2k Changing the regex doesn't make any difference. I event tried just BEGIN
as the regex. There's some kind of fundamental problem in reading the file and converting it to a String
. Let's look at this outside of the weekend :)
With the regex of:
"-----BEGIN PRIVATE KEY-----\\n(.*\\n)-----END PRIVATE KEY-----", Pattern.MULTILINE | Pattern.DOTALL
The output is:
fileExtracter.matches(): false
hardCodedExtracter.matches(): true
Some test code for this available via https://github.com/nexmo-community/nexmo-java-quickstart/blob/master/src/main/java/App.java
This was due to a trailing line break at the end of the PEM file, and the regex for extracting the key data being to strict. I've fixed and am publishing a new SNAPSHOT release.
@leggetter Could you check the new SNAPSHOT release against your test? You may want to use one of the techniques in this slide to make sure the new release is downloaded.
Looks to be resolved. I'm now at #40
Steps to reproduce:
new JWTAuthMethod(applicationId, pathToPrivateKey);
Digging a bit deeper there seems to be something potentially going on with the contents of the file as stored by the CLI. If you output it to stdout then it looks fine. If you copy and past the content into a string the PEM regexp works fine. But reading directly from the file and running the regexp against it fails.
Here's a basic example of a test for this after digging in to the code for
JWTAuthMethod
:Where the output is: