Previously developedQq Internet oauth. Net/MONO/Windows Phone SDK, specific canQq Internet oauth2.0. Net SDK released and sample code for QQ login on the website. In Windows 8, how does the metro program use QQ's interconnected API? Today, we have done some experimental code verification. The biggest challenge to using oauth is to obtain the accesen en. An app accesstoken in oauth is essentially a user's login authentication and permission authorization. After obtaining the user's accesstoken, you can use the accesstoken to send a request to the rest API.
Microsoft has completed the oauth verification library in Metro/winrt, called webauthenticationbroker. He has done a lot of work for us, such as the figure below, using a webbrower on WP7, Metro provides users with a borderless browser window.
This box does not look very nice. I hope QQ Internet can detect the requests initiated from the Windows 8 Metro UI to display more Metro UIS.
Let's take a look at the code. We can't help but sigh that this code is too beautiful. Await on webauthenticationbroker returns an object indicating whether the user has canceled the Code. If an error has occurred, it is still successful.
System. Uri starturi = new uri (tencenturl );
System. Uri enduri = new uri (this. tencentcallbackurl. Text );
Debuuplint ("navigating to:" + facebookurl );
Webauthenticationresult = await webauthenticationbroker. authenticateasync (
Webauthenticationoptions. None,
Starturi,
Enduri );
If (webauthenticationresult. responsestatus = webauthenticationstatus. Success)
{
Outputtoken (webauthenticationresult. responsedata. tostring ());
}
Else if (webauthenticationresult. responsestatus = webauthenticationstatus. errorhttp)
{
Outputtoken ("HTTP Error returned by authenticateasync ():" + webauthenticationresult. responseerrordetail. tostring ());
}
Else
{
Outputtoken ("error returned by authenticateasync ():" + webauthenticationresult. responsestatus. tostring ());
}
}
This code is very concise. It is a cool mechanism. We didn't attach it to the UI code in any way, but it just injects it into one of our own UIS. For how it works, see the msdn document "how Web Authentication broker works". For corresponding code examples, see Web Authentication broker sample. In these examples, Microsoft has implemented several foreign examples: Facebook, Twitter, windows Live, Google, and Flickr services, where there are no localized service examples. Today I have verified the QQ interconnected API on the basis of these examples. The same applies to Renren, Sina, open platforms such as Alibaba and Baidu.
Use Windows runtime and oauth to access online services