public async Task <bool> LoginCallback(Uri url) { if (!url.AbsoluteUri.StartsWith("https://login.live.com/oauth20_desktop.srf")) { return(false); } var result = new AuthResult(url); if (!String.IsNullOrEmpty(result.ErrorCode)) { _liveConnectClient = null; ErrorCode = result.ErrorCode; ErrorDescription = result.ErrorDescription; return(false); } var session = await _authClient.ExchangeAuthCodeAsync(result.AuthorizeCode); _liveConnectClient = new LiveConnectClient(session); ErrorCode = null; ErrorDescription = null; return(true); }
internal static async Task <string> GetToken(Uri url) { // store the token and the code Code = url.Query.Split('&', '=')[1]; var session = await authClient.ExchangeAuthCodeAsync(Code); Token = session.AccessToken; return(Token); }
public async Task <ActionResult> Redirect(string code) { if (code != null) { LiveLoginResult loginStatus = await _liveAuthClient.ExchangeAuthCodeAsync(this.HttpContext); OneNoteCreateViewModel model = await Create(loginStatus.Session); return(View("NewOneNotePage", model)); } else { RedirectToAction("Index", "Home"); } return(null); }
public async Task <LiveLoginResult> Authenticate() { LiveLoginResult result = null; try { //string url = _liveAuthClient.GetLoginUrl(new string[] { "wl.signin", "wl.basic", "wl.emails"}); result = await _liveAuthClient.InitializeWebSessionAsync(new HttpContextWrapper(HttpContext.Current)); if (false) { result = await _liveAuthClient.ExchangeAuthCodeAsync(new HttpContextWrapper(HttpContext.Current)); } _session = result.Session; } catch (LiveAuthException) {} return(result); }
public async Task <ActionResult> Redirect() { var result = await authClient.ExchangeAuthCodeAsync(HttpContext); if (result.Status == LiveConnectSessionStatus.Connected) { var client = new LiveConnectClient(this.authClient.Session); LiveOperationResult meResult = await client.GetAsync("me"); LiveOperationResult mePicResult = await client.GetAsync("me/picture"); LiveOperationResult calendarResult = await client.GetAsync("me/calendars"); ViewBag.Name = meResult.Result["name"].ToString(); ViewBag.PhotoLocation = mePicResult.Result["location"].ToString(); ViewBag.CalendarJson = calendarResult.RawResult; } return(View()); }
internal bool Authorize(HttpContext context, int memberId) { try { var abstractContext = new HttpContextWrapper(context); var result = _liveAuthClient.ExchangeAuthCodeAsync(abstractContext).Result; _session = result.Session; var access = Repository.Queryable <MemberStorageAccess>() .FirstOrDefault( s => s.MemberId == memberId && s.Type == StorageProviderType.OneDrive); if (access == null) { access = new MemberStorageAccess { MemberId = memberId, Token = _session.RefreshToken, Secret = "onedrive", Type = StorageProviderType.OneDrive }; Repository.Add(access); } else { access.Token = _session.RefreshToken; Repository.Update(access); } CheckFolderStructure(); return(true); } catch (Exception ex) { Log.Error(ex); } return(false); }
private async Task getAuthResult() { try { LiveLoginResult result = await liveAuthClient.ExchangeAuthCodeAsync(new HttpContextWrapper(Context)); session = result.Session; new JITAD.UserStats().SendMessage("WebAuth", "jitad", "Inside getAuthResult()"); if (result.Status == LiveConnectSessionStatus.Connected) { var liveClient = new LiveConnectClient(session); var myData = await liveClient.GetAsync("me"); string user_id = myData.Result["id"].ToString(); new JITAD.UserStats().SendMessage("WbAuth", "jitad", "Successfully connected"); getSession(user_id); } } catch (LiveAuthException) { } }
private static async Task <OneDriveClient> OnAuthComplete(LiveAuthClient authClient, AuthResult result) { if (null != result.AuthorizeCode) { try { LiveConnectSession session = await authClient.ExchangeAuthCodeAsync(result.AuthorizeCode); var OneDrive = new OneDriveClient(new LiveConnectClient(session)); return(OneDrive); } catch (LiveAuthException aex) { throw; } catch (LiveConnectException cex) { throw; } } return(null);; }
public async Task <ActionResult> Process(string code) { OneNoteViewModel model = new OneNoteViewModel(); StringBuilder status = new StringBuilder(); Tuple <string, OneNoteNotebook> notebookApiResult = null; Tuple <string, OneNoteSection> sectionApiResult = null; if (code != null) { LiveLoginResult loginStatus = await liveAuthClient.ExchangeAuthCodeAsync(this.HttpContext); // get the selected project string projectId = (string)this.HttpContext.Session["onenote-project"]; ProjectDetailViewModel data = await GetProjectAndReferencesFromSharePoint(projectId); OneNoteRepository repository = new OneNoteRepository(loginStatus.Session); status.Append("GetNotebook: "); notebookApiResult = await repository.GetNotebook("name eq 'Project Research Tracker'"); status.Append(notebookApiResult.Item1 + "<br/>"); OneNoteNotebook notebook = notebookApiResult.Item2; if (notebook == null) { status.Append("CreateNotebook: "); notebookApiResult = await repository.CreateNotebook(); status.Append(notebookApiResult.Item1 + "<br/>"); notebook = notebookApiResult.Item2; } if (notebook != null) { model.NewNotebookLink = notebook.links.oneNoteWebUrl.href; string filter = String.Format("name eq '{0}'", data.Project.Title); status.Append("GetSection: "); sectionApiResult = await repository.GetNotebookSection(notebook, filter); status.Append(sectionApiResult.Item1 + "<br/>"); OneNoteSection section = sectionApiResult.Item2; if (section == null) { status.Append("CreateSection: "); sectionApiResult = await repository.CreateSection(notebook, data.Project.Title); status.Append(sectionApiResult.Item1 + "<br/>"); section = sectionApiResult.Item2; } if (section != null) { foreach (Reference reference in data.References) { status.Append("CreatePage: "); string result = await repository.CreatePageForReference(section.pagesUrl, reference); status.Append(result + "<br/>"); } } } model.ResponseMessage = status.ToString(); return(View(model)); } else { RedirectToAction("Index", "Home"); } return(null); }