1

I am hosting my site in Azure

Azure and Office 365 have same account detail. But when I am using the following code it's giving 403 error.

Also while accessing Azure site I already logged in Office 365 then also not able to take ClientContext. As I am aware i'ts SSO by Azure & Office 365.

 try
 {
     var siteUrl = "https://Office365Site";
     using (var clientContext = new ClientContext(siteUrl))
     {
         clientContext.Load(clientContext.Web, web => web.Title);
         clientContext.ExecuteQuery();
         Response.Write(clientContext.Web.Title);

     }
 }
 catch (Exception ex)
 {
     Response.Write(ex.Message);
 }

Please help in this issue.

0

In order to get detail of Office 365 from Azure we need to context using one of Office 365 account. So it will authorize and return data from office 365.

Please try below code. It may help you.

 try
            {
                var siteUrl = "https://Office365Site";
var tenantAdminUri = new Uri(siteUrl);
                        var clientContext= new ClientContext(tenantAdminUri);

                        SecureString securePassword = new SecureString();
                        foreach (char c in "Your Office 365 user Password")
                        {
                            securePassword.AppendChar(c);
                        }

                        clientContext.Credentials = new SharePointOnlineCredentials("Your Office 365 user Login Email", securePassword);


                    clientContext.Load(clientContext.Web, web => web.Title);
                    clientContext.ExecuteQuery();
                    Response.Write(clientContext.Web.Title);


            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
  • Hi SAM, Why should I enter password? As I already logged in Azure. And From Azure Account I am accessing my web site. Office 365 have same credentials of Azure so I want to use directly ClientContext but it's giving 403 error. – Prashant Shah Feb 8 '17 at 6:28
  • As per my understanding, When you access Office 365 site from azure web domain for both are different. SharePoint is not enable cross domain call directly.Without passing user account how can SharePoint know whether current user is valid or not? So, need to create context using any user account. – Samir Khimani Feb 8 '17 at 6:31
  • Yes I agree with you. But is there any approach to pass context or token to Azure Site to Office 365 Site? – Prashant Shah Feb 8 '17 at 6:34
  • 1
    Yes, but do you use console application to get data from office 365.If yes, then create ClientId and ClientSecret then using Tokenhelper and SharePointcontext class we authenticate with Office 365 using Azure. – Samir Khimani Feb 8 '17 at 6:37
  • Hi Sam, I am using .net web form. Do you have any reference for same scenario? – Prashant Shah Feb 8 '17 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.