I am trying to create RestAPI using Spring boot + Oauth 2.0 and want to access the same from another web application.
My Spring application is deployed at localhost:8585/oauth/token. If i use chrome REST extenstion for calling it works perfectly fine but When i am trying to get the oauth token from my web application using jquery ajax call it gives me following error
'XMLHttpRequest cannot load localhost:8585/oauth/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' localhost:8080' is therefore not allowed access. The response had HTTP status code 401.'
I referred some documentation and @EnableZuulProxy can enable proxy for server but it didnt work
Application.class
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableZuulProxy
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Web Application Page calls oauth/token with clientid , client secret and grant type as client_credential using Jquery ajax call
AND application.yml
zuul:
routes:
resource:
path: oauth/*
url: http://localhost:8080/
stripPrefix: false
and oauth server http configuration as
.antMatchers("/oauth/token").authenticated() .and().csrf().csrfTokenRepository(csrfTokenRepository()).and() .addFilterAfter(csrfHeaderFilter(), CsrfFilter.class);