Get Google login redirect address interface

Retrieve the redirect URL for Google OAuth login, used to implement third-party login functionality, and return the complete Google authorization URL for users to redirect to login.

Points to note

  • This interface uses the GET method, parameters are passed through the URL query string
  • To implement Google OAuth third-party login function
  • Support custom state parameter to prevent CSRF attacks
  • If no state parameter is provided, the system will automatically generate
  • The returned URL contains complete authorization parameters, and the user can jump to the Google login page after visiting
  • You need to configure the relevant parameters of the Google developer account in the background

Request address

{域名地址}/api/google/url

Description:{域名地址}Replace it with your domain name, such ashttps://en.anqicms.com/api/google/url

For complete usage instructions, seeAnqi CMS Google login configuration tutorial

Request Syntax

GET {域名地址}/api/google/url

Request Headers

This interface involves only public request headers. For more information, please refer toCommon Request Headers (Common Request Headers).

Request parameters

Field name Type Required Description
State string No The state parameter of the login redirect address, if not filled in, it will be automatically generated

Response header

This interface only involves public response headers. For more information, please refer toCommon Request Headers (Common Request Headers).

Return parameters

Field name Type Description
code int Error code
msg string Error description
data object Return data content

data parameter

Field name Type Description
State string The state value of the login redirect address
url string Complete Google authorization redirect address

Usage Example

Request example

GET /api/google/url?state=custom-state-value HTTP/1.1
Host: www.anqicms.com

Response Example

{
  "code": 0,
  "msg": "",
  "data": {
    "state": "custom-state-value",
    "url": "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=your-client-id&redirect_uri=https://en.anqicms.com/api/google/callback&scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile&state=custom-state-value"
  }
}

An example request without the state parameter

GET /api/google/url HTTP/1.1
Host: www.anqicms.com

An example response without the state parameter

{
  "code": 0,
  "msg": "",
  "data": {
    "state": "auto-generated-state-12345",
    "url": "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=your-client-id&redirect_uri=https://en.anqicms.com/api/google/callback&scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile&state=auto-generated-state-12345"
  }
}

error code

Error code Description
0 OK
-1 Error, the reason is indicated in msg
1001 Not logged in
1002 Not authorized
200 API request OK