0

I developed a Google OAuth2 Login in Spring Boot and its working fine. I want to redirect to some specific URL after a button has been clicked. I am using an application.yml with Google Oauth2.

I want to redirect to a specific URL after my authentification.

Here is the code I use for Google OAuth2:

Application.yml

security:
  oauth2:
    client:
      clientId: <Google Client Id>
      clientSecret: <Google Secret Id>
      accessTokenUri: https://accounts.google.com/o/oauth2/token
      userAuthorizationUri: https://accounts.google.com/o/oauth2/v2/auth
      clientAuthenticationScheme: form
      scope:
        - openid
        - email
        - profile
    resource:
      userInfoUri: https://www.googleapis.com/oauth2/v3/userinfo
      preferTokenInfo: true 
Turtle
  • 1,626
  • 16
  • 26
  • What's wrong with the code? – Aritz May 04 '17 at 06:10
  • This code is fine. I want to redirect it to some other page – Sahil Arora May 04 '17 at 06:11
  • You want to change the url you're redirected to after the login process? – Aritz May 04 '17 at 06:23
  • I want to make one Html in which when I will login it will do the Oauth autentiction and redirect to some specific URL here in this code I uses Google API but my actual requirement is that one – Sahil Arora May 04 '17 at 06:25
  • The flow for OAuth authentication should be: user requests some url -> if you don't have authorization the server redirects to login page -> the original url is served. Maybe what you want is to modify the first access: ex. user requests `/` and you redirect to `/home.html`. See this: http://stackoverflow.com/a/43697207/1199132 – Aritz May 04 '17 at 06:34
  • In the authorize request towards Google, you should add the redirect_uri parameter. – Mathias Conradt Apr 16 '22 at 17:05
  • u need to add redirect_uri:{your-redirect-uri} to your request – Mohamad Mirzadeh Feb 03 '23 at 12:22

1 Answers1

0

In the authorize request towards Google, you should add the redirect_uri parameter

  security:
    oauth2:
      client:
        clientId: <Google Client Id>
        clientSecret: <Google Secret Id>
        redirectUri: https://YOUR_REDIRECT_URL // *** here ***
        accessTokenUri: https://accounts.google.com/o/oauth2/token
        userAuthorizationUri: https://accounts.google.com/o/oauth2/v2/auth
        clientAuthenticationScheme: form
        scope:
          - openid
          - email
          - profile
      resource:
        userInfoUri: https://www.googleapis.com/oauth2/v3/userinfo
        preferTokenInfo: true 
Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192