/// <summary> /// 构造函数,用于用户接受授权后使用Authorization Code获取AccessToken /// </summary> /// <param name="verifierCode">Authorization Code(注意此code会在10分钟内过期)。</param> /// <param name="state">client端的状态值。用于第三方应用防止CSRF攻击,成功授权后回调时会原样带回</param> public QOpenClient(string verifierCode,string state) { var context = new QzoneContext(verifierCode); if (!string.IsNullOrEmpty(verifierCode)) { this.OAuthToken = context.GetAccessToken(state); } restApi = new RestApi(context); }
public ActionResult LogInQQ() { var context = new QzoneContext(); string state = Guid.NewGuid().ToString().Replace("-", ""); Session["requeststate"] = state; string scope = "get_user_info,add_share,list_album,upload_pic,check_page_fans,add_t,add_pic_t,del_t,get_repost_list,get_info,get_other_info,get_fanslist,get_idolist,add_idol,del_idol,add_one_blog,add_topic,get_tenpay_addr"; var authenticationUrl = context.GetAuthorizationUrl(state, scope); return new RedirectResult(authenticationUrl); }
private void GetRequestToken() { QzoneContext context = new QzoneContext(); string state = Guid.NewGuid().ToString().Replace("-", ""); string scope = "get_user_info,add_share,list_album,upload_pic,check_page_fans,add_t,add_pic_t,del_t,get_repost_list,get_info,get_other_info,get_fanslist,get_idolist,add_idol,del_idol,add_one_blog,add_topic,get_tenpay_addr"; string authenticationUrl = context.GetAuthorizationUrl(state, scope); //request token, request token secret 需要保存起来 //在demo演示中,直接保存在全局变量中.真实情况需要网站自己处理 Session["requeststate"] = state; Response.Redirect(authenticationUrl); }
/// <summary> /// 构造函数,用于用户已经完成授权后,将OAuthToken持久化保存后,使用这个函数从持久化介质中获取到的 /// OAuthToken,进行后续的API调用。 /// </summary> /// <param name="oAuthToken"></param> public QOpenClient(OAuthToken oAuthToken) { this._oAuthToken = oAuthToken; var context = new QzoneContext(oAuthToken); restApi = new RestApi(context); }
public ActionResult QQLogin() { this.Session["RETURNURL"] = callback_qq_url; var context = new QzoneContext(); string scope = "get_user_info"; var authenticationUrl = context.GetAuthorizationUrl("fc", scope); return new RedirectResult(authenticationUrl); }