OAuth2 error message "A required parameter (code) was missing"

OAuth2 error message "A required parameter (code) was missing"

by Pedro Carvalho -
Number of replies: 8

Hi

I need to implement an oauth2 authentication in a moodle platform. I got the client id and secret from a custom service, I made the configurations as instructed by moodle, but in login page, when I try to authenticate with the oauth2 feature, I'm redirected to a screen saying "A required parameter (code) was missing". In moodle docs it is said that this might be a web server misconfiguration. When I try to use the authorization_endpoint directly on google, it works, I'm redirected to the oauth2 service provider site. I would like to know if this problem has other solution besides web server misconfiguration. I would like to know if anyone faced this problem before.

Thanks

Average of ratings: -
In reply to Pedro Carvalho

Re: OAuth2 error message "A required parameter (code) was missing"

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

What's the URL on the page where you see A required parameter (code) was missing? You don't have to share the whole URL just the part after the domain name is enough.

This URL should contain a code= parameter. If that's not present then you will get this error. This reply and this reply have information about the expected parameters in the URL.

In reply to Leon Stringer

Re: OAuth2 error message "A required parameter (code) was missing"

by Pedro Carvalho -
Hi

I see this

/admin/oauth2callback.php#error=unsupported_grant_type&state=/auth/oauth2/login.php?

Regards
In reply to Pedro Carvalho

Re: OAuth2 error message "A required parameter (code) was missing"

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

That's why you see A required parameter (code) was missing – there is no code= in that URL.

It looks like:

  1. Moodle has passed the grant type authorization_code to the OAuth 2 issuer, and
  2. the issuer does not support that grant type and has passed back error=unsupported_grant_type to Moodle.
So you will need to find out what grant types the issuer supports and whether it supports authorization_code. The issuer may have logs to help you investigate this problem.
In reply to Leon Stringer

Re: OAuth2 error message "A required parameter (code) was missing"

by Pedro Carvalho -
Hi

Isn't the authorization code given by the issuer?

Thanks
In reply to Leon Stringer

Re: OAuth2 error message "A required parameter (code) was missing"

by Pedro Carvalho -
Ok, so the issuer says to use response_type with the value "token".
I mean, on authorization endpoint I'm putting this to reach the issuer portal. Is this compatible?

Thanks
In reply to Leon Stringer

Re: OAuth2 error message "A required parameter (code) was missing"

by Pedro Carvalho -
So, the issuer responded and they currently only accepts implicit grant. How to configure moodle for implicit grant?

Thanks
In reply to Leon Stringer

Re: OAuth2 error message "A required parameter (code) was missing"

by Pedro Carvalho -
Hi

Can you help?

Thanks
In reply to Pedro Carvalho

Re: OAuth2 error message "A required parameter (code) was missing"

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

I don't know much about the implicit grant type but I don't think Moodle supports it. For example, in the documentation for setting up Moodle to authenticate with Microsoft service it says Ensure implicit grant flow is disabled.

I think your options are: 1) use an OAuth 2 issuer that supports the authorization code grant type, or 2) implement this in Moodle yourself, either in-house or engage someone to do this.