// Create email with predefine body and subject. SendMessageRequest GenerateEmail(UserInfo to) { return(CreateEmailObject( attachment: to.ItemId == null?new byte[] { 0x20 }: UnifiedApiHelper.GetItem(to.ItemId, (string)Session[SessionKeys.Login.AccessToken]), to: to, subject: Settings.MessageSubject, body: string.Format(Settings.MessageBody, to.Name) )); }
public async Task <ActionResult> SendMessageSubmit(UserInfo userInfo) { // After Index method renders the View, user clicks Send Mail, which comes in here. EnsureUser(ref userInfo); // Send email using the Microsoft Graph API. var sendMessageResult = await UnifiedApiHelper.SendMessageAsync( (string)Session[SessionKeys.Login.AccessToken], GenerateEmail(userInfo)); // Reuse the Index view for messages (sent, not sent, fail) . // Redirect to tell the browser to call the app back via the Index method. return(RedirectToAction(nameof(Index), new RouteValueDictionary(new Dictionary <string, object> { { "Status", sendMessageResult.Status }, { "StatusMessage", sendMessageResult.StatusMessage }, { "Address", userInfo.Address }, }))); }
public async Task <ActionResult> Authorize() { var authContext = new AuthenticationContext(Settings.AzureADAuthority); // Get the token. var authResult = await authContext.AcquireTokenByAuthorizationCodeAsync( Request.Params["code"], // the auth 'code' parameter from the Azure redirect. loginRedirectUri, // same redirectUri as used before in Login method. new ClientCredential(Settings.ClientId, Settings.ClientSecret), // use the client ID and secret to establish app identity. Settings.O365UnifiedAPIResource); // Save the token in the session. Session[SessionKeys.Login.AccessToken] = authResult.AccessToken; // Get info about the current logged in user. Session[SessionKeys.Login.UserInfo] = await UnifiedApiHelper.GetUserInfoAsync(authResult.AccessToken); return(RedirectToAction(nameof(Index), "Message")); }
public async Task <ActionResult> Authorize() { var authContext = new AuthenticationContext(Settings.AzureADAuthority); var authResult = await authContext.AcquireTokenByAuthorizationCodeAsync( Request.Params["code"], loginRedirectUri, new ClientCredential(Settings.ClientId, Settings.ClientSecret), Settings.O365UnifiedAPIResource); // Save the token in the session. Session[SessionKeys.Login.AccessToken] = authResult.AccessToken; // Get info about the current logged in user. Session[SessionKeys.Login.UserInfo] = await UnifiedApiHelper.GetUserInfoAsync(authResult.AccessToken); return(RedirectToAction(nameof(Index), "OneDrive")); }
public FileContentResult Download(string id, string fileName) => File(UnifiedApiHelper.GetItem(id, (string)Session[SessionKeys.Login.AccessToken]), System.Net.Mime.MediaTypeNames.Application.Octet, fileName);