Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Can't communicate with Spring Boot backend #34

Closed
mraible opened this issue Nov 3, 2017 · 2 comments
Closed

Can't communicate with Spring Boot backend #34

mraible opened this issue Nov 3, 2017 · 2 comments

Comments

@mraible
Copy link

mraible commented Nov 3, 2017

I updated my Angular PWA + Spring Boot app today to use Angular 5.

https://developer.okta.com/blog/2017/05/09/progressive-web-applications-with-angular-and-spring-boot

Next, I tried to integrate the latest version of otka-spring-boot-starter and "@okta/okta-angular": "0.0.8". I followed the instructions at https://developer.okta.com/quickstart/angular/default-example, but I can't get the login screen to hide the login button.

Steps to Reproduce

git clone git@github.com:oktadeveloper/spring-boot-angular-pwa-example.git 
git checkout okta-angular-sdk
cd spring-boot-angular-pwa-example/client
npm i
ng serve

You can change the info in src/app/app.module.ts to match your org, or hit me up on Slack and I can provide you some credentials.

@mraible
Copy link
Author

mraible commented Nov 3, 2017

Adding <router-outlet></router-outlet> to app.component.html fixed this issue.

Now I'm having an issue passing the Bearer token to the backend. Here's what my method looks like:

getAll(): Observable<any> {
  const headers: Headers = new Headers();
  if (this.oktaAuth.isAuthenticated()) {
    const accessToken = this.oktaAuth.getAccessToken();
    headers.append('Authorization', accessToken.tokenType + ' ' + accessToken.accessToken);
  }
  const options = new RequestOptions({headers: headers});

  return this.http.get('http://localhost:8080/good-beers', options)
    .map((response: Response) => response.json());
}

The error I see in my console is:

Failed to load http://localhost:8080/good-beers: Response for preflight has invalid HTTP status code 401

I can see the Authorization header is getting added, but the OPTIONS request to http://localhost:8080/good-beers doesn't contain the header.

My server does have CORS enabled with @CrossOrigin(origins = "http://localhost:4200").

Any ideas @bdemers?

@mraible mraible changed the title Can't login with Angular 5 App Can't communicate with Spring Boot backend Nov 3, 2017
@mraible
Copy link
Author

mraible commented Nov 3, 2017

Figured it out - see okta/okta-spring-boot#22 (comment).

@mraible mraible closed this as completed Nov 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant