Comments (5)
I was able to get this figured out and have created a Gist of what I did - it's basically just an integration test as example. You are welcome to use it, or I can fork your project and provide a pull request if you'd like me to.
from spring-rest-service-oauth.
cjstenho In your example unless you're authorized on the client side I thing that connection would throw an exception for not being authorized, and It wont work for non browser clients or when you try to fully automate the process
here I created an example of what I mean
https://github.com/mariubog/oauth-client-sample
It works with Roy Clarkson's example
from spring-rest-service-oauth.
@mariubog - thanks, the integration test works; however, I see what you are saying about requiring a username and password. I will take a look at your example. I am new to OAuth so I am still trying to figure out how all the pieces come together. :-)
from spring-rest-service-oauth.
This is good stuff. An OAuth2RestTemplate
client example would be a very nice addition. Thanks for the suggestion!
from spring-rest-service-oauth.
Very nice and simple example to understand the Oauth02 security implementation.
It would be further good , if we can get a Sample Service(greeting) as a separate component to understand the necessary configuration to protect the service .
Below sample code to get the token can be used:
final String uri = "http://localhost:8080/uaa/oauth/token";
RestTemplate restTemplate = new RestTemplate();
// Create a multimap to hold the named parameters
MultiValueMap<String,String> parameters = new LinkedMultiValueMap<String,String>();
String plainCreds = "clientapp:123456";
byte[] plainCredsBytes = plainCreds.getBytes();
byte[] base64CredsBytes = Base64.encode(plainCredsBytes);
String base64Creds = new String(base64CredsBytes);
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic " + base64Creds);
//parameters.add("clientapp", "123456");
parameters.add("password", "spring");
parameters.add("username", "roy");
parameters.add("grant_type", "password");
parameters.add("scope", "read write");
parameters.add("client_secret", "123456");
parameters.add("client_id", "clientapp");
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));//Accept: application/json
// Create the http entity for the request
HttpEntity<MultiValueMap<String,String>> entity =
new HttpEntity<MultiValueMap<String, String>>(parameters, headers);
ResponseEntity<String> result = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class);
System.out.println("result"+result.getBody().toString());
from spring-rest-service-oauth.
Related Issues (20)
- @EnableWebMvcSecurity is deprecared HOT 1
- Adding new users HOT 3
- Question trying this w/ existing project HOT 1
- How to make this project scalable?
- Add a RESTful api to revoke access tokens?
- NullPointerException on /oauth/check_token with valid token
- Trying to use an html page to get OAuth code instead of curl
- How to access spring-rest-service-oauth to client device ? HOT 1
- Facebook/twitter login? HOT 1
- How to force Spring Security OAuth 2 to use JSON instead of XML? HOT 1
- UserRepositoryUserDetails has to implement abstract method getPassword HOT 1
- If Gson mapper is chosen, the oauth token response is empty HOT 2
- Connect This Project To Mysql HOT 3
- Oauth key annotations are not activated in spring MVC application
- Deployed in AWS Elastic Beanstalk
- What is User credentails to get access token HOT 2
- Project is broken on Spring Boot 1.5.4.RELEASE HOT 2
- UserDetailsService is required for two providers HOT 1
- Refresh token request doesn't work, when used with Spring Security OAuth 2.0.14 HOT 1
- 'entityManagerFactory' in your configuration.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-rest-service-oauth.