#StackBounty: #sharepoint-online #development #microsoft-graph #smtp Authenticate the SmtpClient using AppID and APPSecret instead of p…

Bounty: 100

I have the following SharePoint CSOM code inside my c# console application to send an email using the office 365 admin username and password using the client.Credentials = new NetworkCredential(username, passWord);, as follow :-

 static private void sendemail(ClientContext context, string subject, string body, FieldUserValue[] to, string username, SecureString passWord)
        {

            try
            {
                using (MailMessage mail = new MailMessage())
                {

                    mail.From = new MailAddress("sharepoint@***.com");
                    mail.Subject = subject;
                    mail.IsBodyHtml = true;
                    SmtpClient client = new SmtpClient("***-com.mail.protection.outlook.com", 25);
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.UseDefaultCredentials = false;
                    client.Credentials = new NetworkCredential(username, passWord);
                    client.EnableSsl = true;
                    mail.Body = body;
                    string approvalemailTo = "";

                    foreach (var t in to)
                    {
                        mail.To.Add(t.Email);
                        approvalemailTo = approvalemailTo + t.Email + ";";
                    }
                    client.Send(mail);
                    }
            }


            catch (Exception e)
            {

                   

            }

        }

but to make my code more secure, how i can authenticate the SmtpClient using AppID and APPSecret instead of passing the username and password?

Thanks


Get this bounty!!!

#StackBounty: #azure-active-directory #microsoft-graph Microsoft Graph API intermittent error "Token not found: token is either in…

Bounty: 100

I am making requests to the Microsoft Graph REST api (beta), specifically to the sign-in event endpoint: https://graph.microsoft.com/beta/auditLogs/signIns

I am making batch requests that retrieve sign-ins for a particular user in batches of 1000. Starting around the 25th of september, these requests would fail after roughly 10-50 batches, with the following response, with a 400 (Invalid Request) HTTP error code:

"error": {
  "code": "",
  "message": "Token not found: token is either invalid or expired",
  "innerError": {
    "request-id": "[request-id-redacted]",
    "date": "2019-09-30T22:27:36"
  }
}

However, if I retry the requests after waiting ~1s, with the very same JWT access token, the requests succeed and I’m able to complete all the batch requests for the job I’m running. The access token I receive when initially authenticating expires in 1 hour, but this error crops up ~1-15 minutes after I receive the token (I’ve confirmed the unix timestamp expiry date I get w/ the token).

I’m wondering what could be the cause of this error, and how I could avoid it, other than hard-coding the specific response message and retrying. I was unable to find any matches on google for the error message, either. Has anyone seen this error before from the Microsoft Graph API?


Get this bounty!!!