azizkhani.net

I know that I know nothing

request oauth token by jquery ajax

clock June 10, 2016 15:08 by author Administrator
 
            var atoken;
	    $.ajax({
			  url: "<c:url value = '/api/oauth/token' />",
			  type: 'POST',
			  crossDomain: true,
		      async: false,
		      cache: false,
			  data: {
			    grant_type:'password',
			    username:'admin',
			    password:'admin'
			  },
			  success: function(token, status) {
				  //store.set('token', token);
				  atoken=token;
			  },
			  beforeSend: function (xhr) {
				 xhr.setRequestHeader ("Authorization", "Basic " + btoa("acme:acmesecret" ));
			  }

		});


spring security oauth2 change default prefix path

clock June 8, 2016 23:40 by author Administrator

when add oauth to your project 

oauth library create some endpoint for get token .get authorize code ,get refresh token and some other oauth protocol

this endpoint has rest url s in this url

 

Mapped "{[/oauth/authorize]}

 

Mapped "{[/oauth/token],methods=[GET]}"

 

Mapped "{[/oauth/check_token]}"

,..

 

when your project run in root servlet-path every thing is ok .but when using servlet-path:/api or other name 

request to /api/oauth/token for get token is get exception


for solve this problem need to change default configuration for oauth path for change it nee write this configuration code


@Override

public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {

          endpoints.prefix("/api").authenticationManager(authenticationManager).userDetailsService(userDetailsService).

          accessTokenConverter(jwtAccessTokenConverter());

 




About the author

 Welcome to this web site . This page has two purposes: Sharing information about my professional life such as articles, presentations, etc.
This website is also a place where I would like to share content I enjoy with the rest of the world. Feel free to take a look around, read my blog


Java,J2EE,Spring Framework,JQuery,

Hibernate,NoSql,Cloud,SOA,Rest WebService and Web Stack tech...

RecentPosts

Month List

Sign In