How can I implement OAuth2 with Vaadin - Facebook

Viewed 272

I want to implement OAuth2 with Vaadin 14 and Spring Boot. I'm using Facebook's OAuth2 service.

First I create my login view. It's the main view.

@Route
@PWA(name = "Vaadin Application",
        shortName = "Vaadin App",
        description = "This is an example Vaadin application.",
        enableInstallPrompt = true)
@CssImport("./styles/shared-styles.css")
@CssImport(value = "./styles/vaadin-text-field-styles.css", themeFor = "vaadin-text-field")
public class MainView extends VerticalLayout {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public MainView() {
        Button login = new Button("login");
        login.addClickListener(e->{
            UI.getCurrent().navigate(LoginView.class);
        });
        add(login);
    }

}

Then I create my login view.

@Route("Login")
public class LoginView extends VerticalLayout{

    private static final long serialVersionUID = 1L;

    public LoginView() {

        Label loggedIn = new Label("You are logged in");
        add(loggedIn);
    }

}

Ok! Now I enable OAuth2 for Spring boot.

@EnableOAuth2Sso
@Configuration
public class OAuth2Configuration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .antMatcher("/Login")
                .authorizeRequests()
                .antMatchers("/")
                .permitAll()
                .anyRequest()
                .authenticated();
    }

}

When going from www.localhost:8080 to www.localhost:8080/Login. I can't to be navigated to Facebook's login page. Then when Facebook sending me back. I want to display the email address of the user who just logged in. Just to make sure that specific email addresses can be logged onto my page.

In this case, no Facebook login appears. Just a button, made by my self, appear. When I press on my button, then I standing that I'm logged in.

Here is my application.yml file.

security:
  oauth2:
    client:
      clientId: myCliendID
      clientSecret: myClientSecret
      accessTokenUri: https://graph.facebook.com/oauth/access_token
      userAuthorizationUri: https://www.facebook.com/dialog/oauth
      tokenName: oauth_token
      authenticationScheme: query
      clientAuthenticationScheme: form
    resource:
      userInfoUri: https://graph.facebook.com/me
0 Answers
Related