{"id":17793969,"url":"https://github.com/royclarkson/spring-rest-service-oauth","last_synced_at":"2025-04-04T22:08:01.946Z","repository":{"id":13101047,"uuid":"15782513","full_name":"royclarkson/spring-rest-service-oauth","owner":"royclarkson","description":"A simple OAuth protected REST service built with Spring Boot and Spring Security OAuth","archived":false,"fork":false,"pushed_at":"2015-11-16T22:56:09.000Z","size":1012,"stargazers_count":665,"open_issues_count":22,"forks_count":337,"subscribers_count":58,"default_branch":"master","last_synced_at":"2025-03-28T21:08:14.442Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/royclarkson.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-09T23:13:08.000Z","updated_at":"2025-03-04T00:36:34.000Z","dependencies_parsed_at":"2022-08-23T14:11:11.543Z","dependency_job_id":null,"html_url":"https://github.com/royclarkson/spring-rest-service-oauth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royclarkson%2Fspring-rest-service-oauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royclarkson%2Fspring-rest-service-oauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royclarkson%2Fspring-rest-service-oauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royclarkson%2Fspring-rest-service-oauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/royclarkson","download_url":"https://codeload.github.com/royclarkson/spring-rest-service-oauth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256112,"owners_count":20909240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-27T11:14:43.513Z","updated_at":"2025-04-04T22:08:01.930Z","avatar_url":"https://github.com/royclarkson.png","language":"Java","funding_links":[],"categories":["spring-boot demo"],"sub_categories":[],"readme":"= Spring REST Service OAuth\n\nimage::https://travis-ci.org/royclarkson/spring-rest-service-oauth.svg[Build Status, link=https://travis-ci.org/royclarkson/spring-rest-service-oauth/]\n\nThis is a simple REST service that provides a single RESTful endpoint protected by OAuth 2. The REST service is based on the https://spring.io/guides/gs/rest-service/[Building a RESTful Web Service] getting started guide. This project incorporates the new Java-based configuration support, now available in Spring Security OAuth 2.0. Please log any issues or feature requests to the https://github.com/spring-projects/spring-security-oauth/issues[Spring Security OAuth project].\n\n\n== Spring Projects\n\nThe following Spring projects are used in this sample app:\n\n* http://projects.spring.io/spring-boot/[Spring Boot]\n* http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html[Spring MVC]\n* http://projects.spring.io/spring-security/[Spring Security]\n* http://projects.spring.io/spring-security-oauth/[Spring Security OAuth]\n* http://projects.spring.io/spring-data-jpa/[Spring Data JPA]\n\n\n== Build and Run\n\nUse Gradle:\n\n```sh\n./gradlew clean build bootRun\n```\n\nOr Maven:\n\n```sh\nmvn clean package spring-boot:run\n```\n\n== Usage\n\nTest the `greeting` endpoint:\n\n```sh\ncurl http://localhost:8080/greeting\n```\n\nYou receive the following JSON response, which indicates you are not authorized to access the resource:\n\n```json\n{\n  \"error\": \"unauthorized\",\n  \"error_description\": \"An Authentication object was not found in the SecurityContext\"\n}\n```\n\nIn order to access the protected resource, you must first request an access token via the OAuth handshake. Request OAuth authorization:\n\n```sh\ncurl -X POST -vu clientapp:123456 http://localhost:8080/oauth/token -H \"Accept: application/json\" -d \"password=spring\u0026username=roy\u0026grant_type=password\u0026scope=read%20write\u0026client_secret=123456\u0026client_id=clientapp\"\n```\n\nA successful authorization results in the following JSON response:\n\n```json\n{\n  \"access_token\": \"ff16372e-38a7-4e29-88c2-1fb92897f558\",\n  \"token_type\": \"bearer\",\n  \"refresh_token\": \"f554d386-0b0a-461b-bdb2-292831cecd57\",\n  \"expires_in\": 43199,\n  \"scope\": \"read write\"\n}\n```\n\nUse the `access_token` returned in the previous request to make the authorized request to the protected endpoint:\n\n```sh\ncurl http://localhost:8080/greeting -H \"Authorization: Bearer ff16372e-38a7-4e29-88c2-1fb92897f558\"\n```\n\nIf the request is successful, you will see the following JSON response:\n\n```json\n{\n  \"id\": 1,\n  \"content\": \"Hello, Roy!\"\n}\n```\n\nAfter the specified time period, the `access_token` will expire. Use the `refresh_token` that was returned in the original OAuth authorization to retrieve a new `access_token`:\n\n```sh\ncurl -X POST -vu clientapp:123456 http://localhost:8080/oauth/token -H \"Accept: application/json\" -d \"grant_type=refresh_token\u0026refresh_token=f554d386-0b0a-461b-bdb2-292831cecd57\u0026client_secret=123456\u0026client_id=clientapp\"\n```\n\n\n== SSL\n\nTo configure the project to run on HTTPS as shown in https://spring.io/guides/tutorials/bookmarks/[Building REST services with Spring], enable the `https` profile. You can do this by uncommenting the appropriate line in the application.properties file of this project. This will change the server port to `8443`. Modify the previous requests as in the following command.\n\n```sh\ncurl -X POST -k -vu clientapp:123456 https://localhost:8443/oauth/token -H \"Accept: application/json\" -d \"password=spring\u0026username=roy\u0026grant_type=password\u0026scope=read%20write\u0026client_secret=123456\u0026client_id=clientapp\"\n```\n\nThe `-k` parameter is necessary to allow connections to SSL sites without valid certificates or the self signed certificate which is created for this project.\n\n\n== Cloud Foundry Demo\n\nThe service is deployed to Pivotal Cloud Foundry and available for testing. Modify the previous commands to point to the following URL:\n\n```sh\ncurl http://rclarkson-restoauth.cfapps.io/greeting\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyclarkson%2Fspring-rest-service-oauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froyclarkson%2Fspring-rest-service-oauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyclarkson%2Fspring-rest-service-oauth/lists"}