Authorization mechanism
Calling the Weibo open interface, such as posting Weibo, following, etc., requires user identity authentication. Currently, Weibo open platform mainly uses OAuth2.0 for user identity authentication. In addition, in order to facilitate developers to develop and test their own applications, we also provide Basic Auth identity authentication method, but Basic Auth is only suitable for the developer to whom the application belongs to call the interface.
Quick Index
- Authorization Validity Period
- Extension of the Authorization Validity Period
Overview of OAuth2.0
Compared with OAuth2.0 1.0, the entire authorization verification process is simpler and more secure , which is also the most important user authentication and authorization method in the future.
Regarding the authorization process of the OAuth2.0 protocol, please refer to the flow chart below, where Client refers to the third-party application, Resource Owner refers to the user, Authorization Server is our authorization server, and Resource Server is the API server.
Developers can first browse the interface documentation of OAuth2.0 and become familiar with OAuth2.0 The meaning of the interface and parameters, and then we explain how to use OAuth2.0 according to the application scenarios.
Interface Document
Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Request user authorization Token | |||||||||||||||||||||||||
Get the authorized Access Token | |||||||||||||||||||||||||
Authorization information query interface | |||||||||||||||||||||||||
Authorization recycling interface | ##OAuth2/get_oauth2_token | ||||||||||||||||||||||||
Normal | Authorization validity period | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
30 days |
Extension of the authorization validity periodRe-authorization within the authorization validity periodIf the user is within the authorization validity period Re-open the authorization page for authorization (if the user is logged in to Weibo at this time, this page will flash by), then Weibo will automatically extend the life cycle of the access_token for the developer. Developers are asked to maintain the access_token value after the new authorization. . Refresh the authorization validity period through Refresh TokenIn addition, we also provide a way to refresh through Refresh Token to extend it The authorization is valid, but it should be noted that: Only mobile applications that use the official Weibo mobile SDK can obtain the Refresh Token from the SDK method.
##1. When you are When using the mobile application of Weibo's official mobile SDK, authorization will return an access_token and an additional refresh_token: JSON{ "access_token": "SlAV32hkKG", "remind_in": 3600, "expires_in": 3600 "refresh_token": "QXBK19xm62" } 2、当你调 Use the API interface to return the Access Token When it expires, you can call oauth2/access_token and pass in refresh_token: URL
##{ 3. Use the newly obtained Access Token to call the API
There are two ways to use OAuth2.0 to call API interface:1. Use parameters directly and pass the parameter name access_token URL 2. Pass it in the header, in the form of adding Authorization:OAuth2 space abcd in the header. The abcd here is assumed to be the value of Access Token, and other interface parameters can be passed normally.
Other functions in authorizationScope# #Scope is a function provided by the new version of OAuth2.0 authorization page. Through scope, the platform will open more Weibo core functions to developers, while also strengthening user privacy protection and improving user experience. Users can authorize in the new OAuth2.0 The page has the right to choose the functions given to the application. Scope open interface document: interface document Client default callback pageUsually Mobile Native App does not have a server callback address. You can fill in the default callback page provided by the platform on the authorization callback page of the application console. This page is not visible to users and is only used to obtain access tokens. OAuth2.0 client default callback page: https://api.weibo.com/oauth2/default.html Forced loginThe authorization page will read the Weibo login status of the current user by default. If you want the user to log in again, please pass in the parameters when calling the authorize interface: forcelogin=true, not filling in this parameter by default is equivalent to forcelogin=false. Cancellation of authorization callback pageDevelopers can fill in the cancellation of authorization callback page in the application console. When the user cancels your application authorization, the open platform will call back the address you filled in. And pass you the following parameters, source: application appkey, uid: user who cancels authorization, auth_end: time to cancel authorization OAuth2.0 related resourcesThe following SDK includes OAuth2.0 and the new version of the API interface
Mobile Development SDK Documentation
|