-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add Resource Server Sample #30
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
Conversation
@ketola Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@ketola Thank you for signing the Contributor License Agreement! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you added this under samples
folder. Project does not seem to have gone the multimodule way as there is now a top-level src folder with a sample
package. Not sure this should be cleaned up now or will be part of issue #10 .
@@ -0,0 +1,8 @@ | |||
# See https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2resourceserver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files in /bin
should not be committed. PR #31 adds this folder to .gitignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That slipped in accidentally, it's now removed
} | ||
|
||
test { | ||
useJUnitPlatform() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use JUnit4 or JUnit5 for testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to use junit 5 api, as that was also used in the parent
7c5fc53
to
45abdcd
Compare
I left the module as standalone on purpose as I saw that there was another issue for creating the gradle build. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @ketola. Please see my comments.
@@ -0,0 +1,28 @@ | |||
plugins { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please modify the build to follow the minimal sample, which uses the spring-build-conventions plugin (same as Spring Security).
The build file should be renamed to spring-authorization-server-samples-boot-oauth2resourceserver.gradle
under the boot/oauth2resourceserver
dir.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class SampleResource { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this to something more meaningful? Maybe ResourceController
and resource()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
oauth2: | ||
resourceserver: | ||
jwt: | ||
issuer-uri: https://accounts.google.com |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the jwk-set-uri
property configured with https://localhost:8090/oauth2/keys
.
For the tests, you could either mock the jwkSet endpoint using MockWebServer
or mock()
the JwtDecoder
@Bean
. Take a look at OAuth2ResourceServerConfigurerTests
for examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this one, I will need some more time as I have not used the MockWebServer
before, I'll do some research, check the example and try to finish this later today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I checked out the sample from OAuth2ResourceServerConfigurerTests with the MockWebServer, but It started to feel like a lot's work to get the token validation mocked that way. Instead, I decided to mock the JwtDecoder. Let me know what you think.
@jgrandja, I noticed you labeled this as 'duplicate', where has this work been duplicated? |
@ketola We mark PR's as duplicate if there is an associated issue, which there is in this case. However, we typically mark it when we merge. I'll remove the label until we merge to avoid confusion. |
Thanks for the updates @ketola. This is now in master. |
Add Resource Server Sample
Fixes #4