Authorisation Code

Hi Folks,

For a Nodejs backend application(no express) how can I generate or get the necessary authCode to use within the function
client.loginCodeAuthorizationGrant

I have had read through the documentation and tried the following, is there some way to tap into the response to get the necessary authCode

Thanks,
Paul.

Hello,

The Authorization Code Grant flow is a two-step authentification/authorization process.

A user's browser (or Web component in .Net/Java/... application) must first connect to the Genesys Cloud Authorization Server.
https://login.mypurecloud.com/oauth/authorize?client_id=<my-client-id>&response_type=code&redirect_uri=<http://example.com/oauth/callback>

The user enters his credentials.
Upon successful authentication, the Genesys Cloud Authorization Server will redirect the broswer to the URL you specified as redirect URI in the first step.
This request will contain the authorization code as a query parameter.
Ex: http://example.com/oauth/callback?code=my-authorization-code

The example.com must correspond to your backend server application which will receive this HTTP request.
It can then extract the code from the url and perform a query to get an authorization/bearer token from this authorization code.

You can also check this tutorial on Authorization Code Grant.

If your idea is to leverage the Authorization Code Grant flow, without having a user enter his credentials via the login web page of the Genesys Cloud Authorization Server, then it is not possible.

Regards,

Thanks For Replying Jerome,

Regarding the first step of the process, I don't get any window launch looking for my credentials, is the expectation the first step will need to be or has to be initiated via user action on the frontend.

"https://login.mypurecloud.ie/oauth/authorize?client_id=xxxxxxxx&response_type=code&redirect_uri=http://localhost:4000/oauth2/callback

Thanks,
Paul

Yes.

The example would be the following (assuming your backend "speaks" HTTP - i.e. acts as a web server).
A user connects to a page that your server manages.
The server checks if there is a session cookie (something your server would set) to see if it can recognize the user connecting, and if this user already authenticated.
If there is no session cookie (or it is unknown), your server requests the user to authenticate first with Genesys Cloud, redirecting him to the Genesys Cloud Authorization server (the https://login.mypurecloud.ie/oauth/authorize url)

That's what the tutorial I referenced is showing.

Code of nodejs and of a sample html page is here
User would open the page at https://yournodejsserver/my_info.html on his web browser

But you could also have the user opens his webclient at the following url directly: https://login.mypurecloud.ie/oauth/authorize?client_id=<my-client-id>&response_type=code&redirect_uri=<http://example.com/oauth/callback>
This is if your server/backend does not manage a session cookie (of your own) and just needs to get the authorization-code when the user is redirected to the Redirect URI after successful authentication/authorization on the Genesys Cloud login url.
It would mean you would trigger an authorization flow every time the user opens this url. It is not optimized. But it would still work.

JSM

Okay, Thanks for the help Jerome.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.