13
Views
9
Comments
Solved
[Adobe IMS Token Exchange] Error creating access token - Unable to cast object of type
Question
adobe-ims-token-exchange
Service icon
Forge asset by Stefan Weber
Application Type
Service

Hi,

I just installed your service and have encountered the following problem I cannot solve.

I created my credentials @ adobe.io, downloaded the credentials zip and opened the files private.key and pdfservices-api-credentials.json (in varying editors such as notepad, brackets etc.)

I copied and pasted the relevant fields to your app (being especially careful of the private.key content)

I keep getting the error:

Unable to cast object of type 'Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair' to type 'Org.BouncyCastle.Crypto.Parameters.RsaPrivateCrtKeyParameters'.

Could you give me some direction on how to resolve this?

Cheers, Mark

OS Version 11.19.0 (Build 38072) 

2021-10-09 07-57-44
Stefan Weber
 
MVP
Solution

Hi Mark,

i notice that your private key ist starting with BEGIN RSA PRIVATE KEY. Where did you get that private key from? Iam asking because when you create a public/private key pair in Adobe Developer Console you should get an PKCS#8 formatted pem which should start with BEGIN PRIVATE KEY. The code iam using to construct and sign the access token is currently only supporting pkcs#8 pem which is - at least from my knowledge - the only format you should get from Adobe.

You can create a new private/public key pair using the Adobe Developer Console 

Best

Stefan

2014-09-04 01-10-12
Mark Bayles

Hi Stefan,

I got this from the adobe.io console (as you mentioned in your documentation) 

I did look to see when creating my credentials that I could create using another method, but I cannot seem to find that option as I also noted in one of your messages that you were expecting BEGIN PRIVATE KEY not BEGIN RSA PRIVATE KEY 

I will look further to see if I can change how it creates the creds.


Thanks, Mark

2021-10-09 07-57-44
Stefan Weber
 
MVP

Pretty weird. I just created a new private / publick key pair in the console and did get a PKCS#8 formatted private key. The format you are getting is the outdated pkcs#1 format. 

2014-09-04 01-10-12
Mark Bayles

Hi Stefan,

Figured it out. The issue was that the "Generate Credentials" was for the generic access to the adobe.io but per your screenshot under the project / credentials / service account I was able to generate the private key there which then worked.


Thanks for your prompt response and assistance.


Regards, Mark

2021-10-09 07-57-44
Stefan Weber
 
MVP

Thank you Mark. I didn't know that there is a difference between the two approaches and i will update my article accordingly.

2014-09-04 01-10-12
Mark Bayles

It seems to be an Adobe "feature" as I was not able to recreate how I originally did it, so I just created a new account for testing purposes and was able to do it again.

Steps were;

1) Create a new account in adobe.io

2) Go to products and select "Adobe PDF Servies API free trial"

3) Create credentials

4) This is where it generates the credentials zip with the old version of the private key (which does not work)

Not sure if this is intentional by Adobe or not but that is what caused my issue.

HTH with the documentation.

Cheers, Mark


2021-10-09 07-57-44
Stefan Weber
 
MVP

Thanks alot Mark for reproducing the issue!

2021-10-09 07-57-44
Stefan Weber
 
MVP

Yesterday i received a mail from Adobe that it is now possible to get an access token via OAuth client credential flow and that the JWT exchange method is deprecated (will work until mid 2025 though). I updated the forge component to request an access token with the new client credentials flow.

2014-09-04 01-10-12
Mark Bayles

Hi Stefan,

I was going to write to you about that as I received the same email last night but as its the afternoon here in Australia my mind switched to drinking a beer! 

But thanks for doing this - your components are excellent!

Cheers, Mark


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.