public void LineLogin([FromQuery] LineAuthorizeModel lineAuthorize) { string Uri = string.Empty; try { #region --登入發生錯誤-- if (lineAuthorize.Error != null) { //TODO:錯誤處理 Uri = "/Home/Error"; } #endregion else { LineLoginBLL lineLoginBLL = new LineLoginBLL(_settings, _resultModel, _httpClientFactory); LineProfile Data = lineLoginBLL.GetLineAccount(lineAuthorize); _sessionHelper.SetSession("Nickname", Data.displayName); Uri = "/Home/Wellcome"; } } catch (Exception ex) { Uri = "/Home/Error"; } finally { Response.Redirect(Uri); } }
/// <summary> /// 取得Line會員資料 /// </summary> /// <param name="lineAuthorize"></param> /// <returns></returns> public LineProfile GetLineAccount(LineAuthorizeModel lineAuthorize) { LineLoginProjectSetting lineSetting; if (true) { lineSetting = _line.LineLogin.RightTY; } LineTokenModel lineTokenModel = GetLineAccountToken(lineAuthorize, lineSetting); HttpClientHelper <LineProfile> httpClientHelper = new HttpClientHelper <LineProfile>(_httpClientFactory); httpClientHelper.SetHeaders("Authorization", "Bearer " + lineTokenModel.Access_Token); return(httpClientHelper.SendAsync(HttpMethod.Get, lineSetting.Profile.ProfileUri.ToString())); }
/// <summary> /// 取得Line會員Access_Token /// </summary> /// <param name="lineAuthorize">line Authorize GetCode Model</param> /// <returns></returns> public LineTokenModel GetLineAccountToken(LineAuthorizeModel lineAuthorize, LineLoginProjectSetting lineSetting) { Dictionary <string, string> dic = new Dictionary <string, string>() { { "grant_type", lineSetting.Token.GrantType }, { "code", lineAuthorize.Code }, { "redirect_uri", lineSetting.Token.RedirectUri.ToString() }, { "client_id", lineSetting.ClientId }, { "client_secret", lineSetting.ClientSecret } }; HttpClientHelper <LineTokenModel> httpClientHelper = new HttpClientHelper <LineTokenModel>(_httpClientFactory); LineTokenModel lineTokenModel = httpClientHelper.SendAsync(HttpMethod.Post, lineSetting.Token.TokenUri.ToString(), dic); return(lineTokenModel); }
public ActionResult Index() { //取得LineToken HttpCookie cookie = Request.Cookies["LineToken"]; //如果沒有token 先取得自己Notify的資料 if (cookie == null || String.IsNullOrEmpty(cookie.Value)) { ViewBag.Title = "Line Notify"; //HttpGet LineAuthorizeModel model = new LineAuthorizeModel() { response_type = "code", client_id = ConfigurationManager.AppSettings["ClientID"], redirect_uri = ConfigurationManager.AppSettings["RedirectUri"], scope = "notify", state = Guid.NewGuid().ToString(), responsemode = "form_post" }; return(View(model)); } //有token的話 前往Notify功能 return(RedirectToAction("Notification", "Line")); }