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

How to document the oauth endpoints? #2094

Closed
sskjames opened this issue Feb 27, 2023 · 8 comments
Closed

How to document the oauth endpoints? #2094

sskjames opened this issue Feb 27, 2023 · 8 comments
Labels
enhancement New feature or request

Comments

@sskjames
Copy link

First of all, thank you very much to all concerned for creating/maintaining this project.
I checked the project documentation on how to document the security endpoints (e.g outh2/token) but I couldn't find much information except the suggestion to include springdoc-openapi-security. It also has this point:
This dependency helps ignoring @AuthenticationPrincipal in case its used on REST Controllers..
It's not clear to me that whether including this dependency will help list the security endpoints in the generated docs. Also I couldn't find info on how to add custom documentation for these security endpoints.
Have I missed something? Can someone please help me?

Thanks
James

@sskjames
Copy link
Author

Here is a minimal working sample application.
spring-oauth-springdoc-demo.zip

Basically I'm using:
Spring Boot: 2.7.x
Spring Authorization Server: 0.4.1
SpringDoc: 1.6.14

I'm only able to see only one endpoint (/hello) in the generated doc.
I'd like the /oauth2/token endpoint to be listed in the doc.

@bnasslahsen bnasslahsen added the enhancement New feature or request label Mar 7, 2023
@bnasslahsen
Copy link
Contributor

@sskjames,

Spring Authorization Server was not yet supported.
I have added a property to enable the support:

springdoc.show-oauth2-endpoints=true

You can already do your tests with the latest SNAPSHOT and provide your feedback before the next release.

@sskjames
Copy link
Author

sskjames commented Mar 8, 2023

@sskjames,

Spring Authorization Server was not yet supported. I have added a property to enable the support:

springdoc.show-oauth2-endpoints=true

You can already do your tests with the latest SNAPSHOT and provide your feedback before the next release.

Hi @bnasslahsen, thank you very much for addressing this concern.
I tested this with 1.6.15-SNAPSHOT and I could see all the authorization server endpoints once I configured specified property.
Does springdoc provide the ability to customize the documentation generated for these endpoins just like we do with the @Operation annotation for regular endpoins?

Screenshot from 2023-03-08 11-16-21

@bnasslahsen
Copy link
Contributor

@sskjames,

You could use GlobalOpenApiCustomizer to adapt the generated openAPI definition. This is the recommended way.
Another alternative, you can use your own bean SpringDocSecurityOAuth2Customizer to override the existing logic.

@uc4w6c
Copy link
Collaborator

uc4w6c commented Mar 9, 2023

@bnasslahsen
Thank you for supporting Spring Authorization Server.

The column of response body is camel case, but snake case is actually returned.

example (/.well-known/oauth-authorization-server)

actual response

{
   "issuer": "http://localhost:8080",
   "authorization_endpoint": "http://localhost:8080/oauth2/authorize",
   "token_endpoint": "http://localhost:8080/oauth2/token",
   "token_endpoint_auth_methods_supported": [
     "client_secret_basic",
     "client_secret_post",
     "client_secret_jwt",
     "private_key_jwt"
   ],
   ...
}

スクリーンショット 2023-03-09 22 54 27

api-docs schema

			"OAuth2AuthorizationServerMetadata": {
				"type": "object",
				"properties": {
					"issuer": {
						"type": "string",
						"format": "url"
					},
					"authorizationEndpoint": {
						"type": "string",
						"format": "url"
					},
					"tokenEndpointAuthenticationMethods": {
						"type": "array",
						"items": {
							"type": "string"
						}
					},
					...
				}
			}

スクリーンショット 2023-03-09 22 54 37


The springdoc code uses OAuth2AuthorizationServerMetadata when creating a schema, but in AbstractOAuth2AuthorizationServerMetadata inherited by this class, OAuth2AuthorizationServerMetadataClaimNames is used for each column to determine the column name for response.

example

https://github.com/spring-projects/spring-authorization-server/blob/ad01779479d72ede119c1d6110edc3fa9d1bff3a/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/AbstractOAuth2AuthorizationServerMetadata.java#L96

Therefore, it is difficult to obtain the value, so I think it is better to define the schema for each field.
However, when the Spring Authorization Server changes the response format, the springdoc also needs to be modified, which may be a concern for maintainability.
(Various responses are RFC compliant, so I don't think the response columns change frequently.)
What do you think?

There are a lot of revisions, so if there is anything I can do, I will be happy to help.

@bnasslahsen
Copy link
Contributor

@uc4w6c,

This is the kind of feedback i was expecting.
Agree with your approach.
If you want go for it, please feel free to propose a PR.

bnasslahsen added a commit that referenced this issue Mar 9, 2023
bnasslahsen added a commit that referenced this issue Mar 9, 2023
bnasslahsen added a commit that referenced this issue Mar 9, 2023
@shrralis
Copy link

@bnasslahsen is it possible to add support for /.well-known/openid-configuration and other OIDC endpoints of Spring Authorization Server as well?

@uc4w6c
Copy link
Collaborator

uc4w6c commented Oct 23, 2023

@shrralis
Already committed. (#2340)
It will be available from the next version.

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

No branches or pull requests

4 participants