Understanding the OAuth Authorization Flow Using a WeChat Login Example
This article explains the OAuth authorization process, illustrating how a third‑party app like a WeChat‑based login requests user permission, obtains a code, exchanges it for an access token, and uses that token to access user data, while highlighting token expiration and business‑scenario applications.
We often use third‑party accounts to log into platforms, such as using a QQ account for iQiyi or a Weibo account for the Ziroom app. During login, the platform requests permission to access the user's public profile or other data, which follows a complex OAuth authorization flow.
The article uses a WeChat login to Ziroom as an example: the app asks for access to the user's WeChat public information, and when the user confirms, the OAuth process begins.
The main steps of the OAuth flow are:
1. The user initiates login with WeChat. 2. Ziroom requests permission to access the user's WeChat profile. 3. The user agrees. 4. Ziroom receives a callback URL and requests a code from the WeChat server. 5. WeChat returns the code . 6. Ziroom exchanges the code and callback URL for an access_token . 7. WeChat returns the access_token . 8. Ziroom uses the access_token to retrieve the user's WeChat data.
Key points to note:
1. The code is time‑limited and should be exchanged for an access_token within a few minutes. 2. The access_token also expires, requiring a new token to be obtained after expiration.
In business scenarios, third‑party devices or services often need similar OAuth authorization to allow a private cloud to access or control devices hosted on another cloud; the flow remains essentially the same.
Conclusion: The author encountered this flow during IoT cloud testing and now understands the OAuth process for third‑party logins. For deeper details, one can study the OAuth authentication principles.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.