Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why I'm getting "OAuth Flow is missing defined scopes" problem if scopes are optional in oauth2? #527

Closed
danielSenpaiDev opened this issue Oct 13, 2022 · 6 comments
Assignees
Labels

Comments

@danielSenpaiDev
Copy link

danielSenpaiDev commented Oct 13, 2022

Hi!
I'm using using Data Models to validate some API definitions. In any API with oauth2 authorization type I'm getting in the ValidationProblems list that issues found are "OAuth Flow is missing defined scopes", this one with medium severity.

For example, I have the following security schemes:

components:
    securitySchemes:
        application:
            flows:
                clientCredentials:
                    tokenUrl: 'https://myserver.com/login/v2/authorization'
                    scopes: {}

But this should be valid, however the validation returns that is not. I'm using the Apicurio Data Models library version 1.1.26 on Java, as far as I'm aware, 1.1.26 is compliant with OAS 3.0.2.

I'm using this code (I'm using the deprecated method because I couldn't find usage documentation about the new one):

        Document api = null;
        List<ValidationProblem> problems = null;
        // There is no documentation about the new validateDocument method. So, I'm forced to use the deprecated one.
        try {
            api = Library.readDocumentFromJSONString(contract);
            problems = Library.validate(api, null);    
        } catch (Exception e) {
            log.error("Error analizing OAS3 validation", e);
            return false;
        }

the "problems" object comes with an element with the message "OAuth Flow is missing defined scopes" described.

So I need your help guys, anyone can help me if this is ok, please? or it's an issue? or I'm doing something wrong?

Thanks in advance.

@EricWittmann
Copy link
Member

I'll need to dig into the specification again to determine why a given validation rule is being triggered. It's certainly possible that there is simply a bug in the validators.

Note that it's possible to enable/disable individual rules if you either think they aren't working properly or you simply don't care about them.

@EricWittmann
Copy link
Member

OK I've investigated this and verified that it's a bug in the library. It turns out that our reader can't tell the difference between an empty map and a map with no items in it. The offending code is here:

https://github.com/Apicurio/apicurio-data-models/blob/main/src/main/java/io/apicurio/datamodels/core/io/DataModelReader.java#L409-L414

Combined with this:

https://github.com/Apicurio/apicurio-data-models/blob/main/src/main/java/io/apicurio/datamodels/core/models/common/OAuthFlow.java#L48-L53

An empty map will result in no called to addScope. Because the map is lazily created, empty map and no-map look the same after the reader is done.

I'll fix the bug. :)

@EricWittmann EricWittmann self-assigned this Nov 14, 2022
EricWittmann added a commit that referenced this issue Nov 14, 2022
@EricWittmann
Copy link
Member

Fixed in 98b4557

@danielSenpaiDev
Copy link
Author

danielSenpaiDev commented Nov 14, 2022 via email

@EricWittmann
Copy link
Member

I will kick off a release right now! :)

@danielSenpaiDev
Copy link
Author

danielSenpaiDev commented Nov 16, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants