Unable to login with oauth2 setup with wso2 using custom login page

Unable to login with oauth2 setup with wso2 using custom login page

by Rakesh Bhatt -
Number of replies: 1

I had a custom application login and I want to perform login to Moodle using that login.

I have set up wso2 identity server and created a service provider for moodle which is configured properly with moodle.

In moodle also I have setup OAuth Plugin and created fields respectively. Login is working fine if I do it as a custom oauth button on login page in moodle

If I try to recreate a similar auth flow inside the custom login page with Oauth2 and credentials of wso2 service provider configured in WSO2

I am getting into lots of issues

With wso2 I am getting user auth token from wso2 I am able to retrieve moodle redirect URL :

http://x.x.x.x/moodle/admin/oauth2callback.php?code=xxxx-xxxxx-xxxx-xxxxx-xxxxx&session_state=xxxxxxx=

Initially, when I redirect to this URL it gave an error state not found so after a long search I added state parameter in redirected url 

The new redirection URL is below

http://x.x.x.x/moodle/admin/oauth2callback.php?code={{auth_code}}&state=%2Fauth%2Foauth2%2Flogin.php%3Fwantsurl%3Dhttp%253A%252F%252Fxx.xx.xx.xx%252Fmoodle%252F&session_state={{session_state}}

Now as I redirect to this URL it is showing

Your session has most likely timed out. Please log in again.

I try it from moodle trying to log in from moodle home page using the wso2 auth button it is working

I am not able to figure out if I am missing configuration or anything else

For setting up moodle and oath I took help from the below blog

https://dinika-15.medium.com/integrating-moodle-with-wso2-identity-server-3a5a6778d80#:~:text=Under%20Server%20tab%2C%20click%20on,the%20name%20we%20add%20here.

Please help


Average of ratings: -
In reply to Rakesh Bhatt

Re: Unable to login with oauth2 setup with wso2 using custom login page

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

I don't know anything about using a custom login page but in the state parameter of the callback URL there should be a sesskey parameter as a URL-encoded value. The callback URL has two parameters: code and state, and state is a URL-encoded resource containing the parameters as shown below:

Example callback URL: /admin/oauth2callback.php?code=f132…&state=%2Fauth%2Foauth2%2Flogin.php%3Fwantsurl%3Dhttps%253A%252F%252Fmoodle.example.com%252F%26sesskey%3DGZlz8cFzkd%26id%3D1

  1. wantsurl: In the above example URL:
    state=%2Fauth%2Foauth2%2Flogin.php%3Fwantsurl%3Dhttps%253A%252F%252Fmoodle.example.com%252F%26sesskey%3DGZlz8cFzkd%26id%3D1
  2. sesskey: In the above example URL:
    state=%2Fauth%2Foauth2%2Flogin.php%3Fwantsurl%3Dhttps%253A%252F%252Fmoodle.example.com%252F%26sesskey%3DGZlz8cFzkd%26id%3D1
  3. id: In the above example URL:
    state=%2Fauth%2Foauth2%2Flogin.php%3Fwantsurl%3Dhttps%253A%252F%252Fmoodle.example.com%252F%26sesskey%3DGZlz8cFzkd%26id%3D1
I think the Your session has most likely timed out message is because there's no sesskey in the URL-encoded state parameter.