Retrieve the redirect URL for Google OAuth login, used to implement third-party login functionality, and return the complete Google authorization URL for user login redirection.
Precautions
- This interface uses the GET method, parameters are passed through the URL query string
- Used to implement Google OAuth third-party login function
- Supports custom state parameters to prevent CSRF attacks
- If the state parameter is not provided, the system will automatically generate
- The returned URL contains complete authorization parameters, and the user can be redirected to the Google login page after visiting
- Need to configure the relevant parameters of the Google developer account in the background
Request address
{ๅๅๅฐๅ}/api/google/url
Description:{ๅๅๅฐๅ}Need to replace it with your domain address, such ashttps://en.anqicms.com/api/google/url
For the complete usage method, refer toSafe CMS Google login configuration tutorial
Request syntax
GET {ๅๅๅฐๅ}/api/google/url
Request header
This interface only involves 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 for the login redirect address, it will be automatically generated if not filled in |
Response Headers
This interface only involves public response headers. More information, please refer toCommon Request Headers (Common Request Headers).
Return parameters
| Field Name | Type | Description |
|---|---|---|
| code | integer | Error code |
| message | string | Error Description |
| data | object | Return data content |
data Parameter
| Field Name | Type | Description |
|---|---|---|
| state | string | The state value for the login redirect address |
| URL | string | The complete Google authorization redirect address |
Example Usage
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"
}
}
Example of request without state parameter
GET /api/google/url HTTP/1.1
Host: www.anqicms.com
Example of response without 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 | Unauthorized |
| 200 | API request OK |