A. ConceptThe OAuth protocol provides a secure, open, and easy standard for the authorization of user resources. Unlike previous licensing methods, OAuth's authorization does not allow a third party to touch the user's account information (such as a user name and password), which means that the third party can request authorization for the user's resources without using the user's username and password, so OAuth is secure. OAuth is a shorthand for open authorization.
B. Using 3 stepsOAuth authentication Authorization in three steps, three sentences can be summed up: 1. Gets the unauthorized request Token2. Gets the user-authorized request Token3. Redeem access token with authorized request token
One, XX Weibo---> Users Weibo data 1. Become a Sina developer (to join the development camp of Sina Weibo)
* Sign up for a Weibo account, login http://open.weibo.com
Account Number: XXXXXX
Password: xxxxxx
* Fill in the developer's personal information (such as name, date of birth, upload ID)
2. Create an App
* Assuming the application name is called "xx Weibo"
* When the app is created, it enters the "development" phase by default and is eligible for authorization
* Application Related Data
App key:3145626526//Unique identifier of the app
APP secret:ee9de4d2431be061b22fe328332a1111
Redirect uri:http://www.baidu.com
3. User authorization of "xx Weibo" resources----OAuth Authorization 2.0
1> obtaining an unauthorized request Token: Display the login page provided by the server provider
* Url:https://api.weibo.com/oauth2/authorize
* Parameters
client_id true string to assign when applying appkey//To know which app to authorize
Redirect_uri true string to authorize callback address//to which page to jump after authorization succeeds
2> obtaining the Authorized request Token
* After the authorization succeeds, automatically jumps to the callback page, for example
http://www.baidu.com/?code=eabdc03cc4cc51484111b1cfd9c4cd0b
Sina will append a parameter after the callback page: request Token after authorization is successful
3> in exchange for an access token based on the authorized request token
* Url:https://api.weibo.com/oauth2/access_token
* Parameters
client_id true string to be assigned when applying the Appkey.
Client_secret true string to be assigned when applying the Appsecret.
Grant_type true string request type, fill in Authorization_code
Code true string calls the code value obtained by authorize.
Redirect_uri true string callback address, which needs to be consistent with the callback address in the registration application
* Return Results
{
"Access_token" = "2.00vwf4geuska7d739148f7608sxa9b";
"Expires_in" = 157679999;
"Remind_in" = 157679999;
UID = 3758830533;
}
UID = = USER_ID = = ID of the current logged on user = = User's unique identity
{
"Access_token" = "2.00vwf4geuska7d739148f7608sxa9b";
"Expires_in" = 157679999;
"Remind_in" = 157679999;
UID = 3758830533;
}
* Access_token and UID of the Go Bai
Access_token:1 users to 1 applications after the successful authorization, the corresponding 1 Access_token, the role is: Allow 1 applications to access 1 users of data
Uid:1 user for 1 uid, every 1 users have their own unique UID
Example:
Tom
John doe
Application 1
Application 2
Zhang San to Application 1, Application 2 authorization succeeded: 1 UID, 2 Access_token
John Doe to Application 2 authorization succeeded: 1 UID, 1 access_token
Above operation: produced 2 uid,3 of Access_token
Second, the authorization process common error:
1.invalid_request
1> no required request parameters are passed
2> request parameter is not correct
3> a space in the middle of the URL
2.invalid_client
1> client_id Value Pass error (Appkey is not correct)
3.redirect_uri_mismatch
1> callback address is not correct
Third, the authorized account Note 1. If the app has not been reviewed by Sina, it can only access its own or 15 other test account micro-blog Data A
[iOS Weibo Project-2.0]-OAuth authorization 3 steps