How to decrypt the refresh token and get the access token in oauth 2 integration

Divya2411
Tera Contributor

Hi,

I am trying to generate access token using third party integration, getting the physical refresh token but not able to encrypt that token and generate the access token . I am using the application scope and getting the error that you cant use the  GlideEncrypter() method in the application scope .

Kindly help me in this, how can we encrypt the token and get the access token . I tried several code from community for that but its not working for my application scope.

 

 

@Ankur Bawiskar

4 REPLIES 4

Rahul Kumar17
Tera Guru

Hi @Divya2411 ,

 

It sounds like you're trying to use the GlideEncrypter() method within the application scope, but you're receiving an error message indicating that this is not allowed.

The reason for this error message is that the GlideEncrypter() method is only available within a session scope, not within an application scope. This means that you will need to use a different approach to encrypt the refresh token.

One possible solution is to use a server-side encryption library, such as OpenSSL or BouncyCastle. These libraries provide a range of encryption algorithms that can be used to securely encrypt data, including the refresh token.

Here's a general overview of how you might use one of these libraries to encrypt the refresh token:

  1. Generate a symmetric encryption key. This key will be used to encrypt and decrypt the refresh token.

  2. Encrypt the refresh token using the encryption key.

  3. Store the encrypted refresh token in a secure location, such as a database or a file.

  4. When you need to generate an access token, retrieve the encrypted refresh token and decrypt it using the same encryption key.

  5. Use the decrypted refresh token to generate the access token.

It's worth noting that encryption is a complex topic, and there are many factors to consider when implementing encryption in a secure and reliable way. If you're not familiar with encryption, it may be a good idea to seek the assistance of a security expert or consultant to help ensure that your implementation is secure and effective.

I hope this information helps you to get started with encrypting your refresh token and generating access tokens. If you have any further questions or concerns, feel free to ask.

 
Thanks,
Rahul Kumar
If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

Hi @Rahul Kumar17 

 

Thanks for help,

But how we can generate symmetric encryption key. can you explain me the steps, I am new to the servicenow platform. i don't have any idea.

Ankur Bawiskar
Tera Patron
Tera Patron

@Divya2411 

can you share your existing script?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

for encryption I am using this:-

 

var encrypter = new GlideEncrypter();
var encryptval ="ļ·žļ·Ÿļ·’3a35af871b3c21109c8d1f47b04bcb9e﷬﷔1﷬﷭92TT-ATzXdXbvzVrkEbGSg==5nZ2qszvqwbl2hdFFwYQhlgT9AKXOFmIZ6_8z1ikdYe8O1iZ9rzVAG8a-sVUxXxv7Ns_pjdlMHVo2n5vAjIwfp5fPJuDljN4ZFoIJnlYgOn10Vnm-AIMpw8eQ-hInK8ewTxJPr5D6CVeABRitw9Xfi28fgC37I8m-Ae4w--aMa7ROXIriU0J2FH2CzHuWc38AFv617XsfEkKEnAXME-ST11l3JJZfvXYO6H5UqihlPD7xLaB7Mkc1uitApk5CjBOVGKuy_d7_gDl40JJrQvXjo5gvPkFimEeGr9HJeHcxz7b6OX-7EM5x3G8R4lscF1gAcPrx6GhtYn2u1LFlbM3oIc8btHVacB-mVOPtJA-qPkLNDVExFJAflLVvRaZr_OzbprAmUm7yVN0X2p_RwoUTF1XYGqUnBlBevxLMaApEg7qDFsst3kn9lZy9bY-Rs-jxWSx0ot3E01464O_JE1sjS6tpQqLqw8PT-rnmvJ8dEyG2Po-6iXnMup-IB1vHXVMSNOGUJ043bLZhwupRduvE3r3RSKDxaQie4_8e_p2ncoXJfJWHtEV8mAFc0cngO3RnBlzt---8CQJNUJG7FIWIGO-daAvZQTh5V6wyHQmLhG7u1aQ5sgFl-KGv7xeXplFXsXPsVNxQbm8fe687oyDv4kTgDcv0dOM﷮﷯";
var encrString = encrypter.encrypt(encryptval);
gs.info("encrypted string = " +encrString );