Пример #1
0
            internal static async Task <Office365ServiceInfo> CreateAsync()
            {
                // For Exchange, the resource ID and API Endpoint are static for the public O365 cloud.
                Office365ServiceInfo info = new ExchangeServiceInfo()
                {
                    ResourceId  = "https://outlook.office365.com/",
                    ApiEndpoint = "https://outlook.office365.com/ews/odata"
                };

                info.AccessToken = await Office365Helper.GetAccessToken(info.ResourceId);

                return(info);
            }
Пример #2
0
            public static async Task <ActiveDirectoryServiceInfo> CreateAsync()
            {
                // For Active Directory, the resource ID and API Endpoint are static for the public O365 cloud.
                ActiveDirectoryServiceInfo info = new ActiveDirectoryServiceInfo
                {
                    ResourceId  = "https://graph.windows.net/",
                    ApiEndpoint = "https://graph.windows.net"
                };

                info.AccessToken = await Office365Helper.GetAccessToken(info.ResourceId);

                return(info);
            }
Пример #3
0
            internal static async Task <DiscoveryServiceInfo> CreateAsync()
            {
                DiscoveryServiceInfo info = new DiscoveryServiceInfo()
                {
                    // In the initial Preview release of Service Discovery, you must use a temporary Resource ID
                    //     for Service Discovery ("Microsoft.SharePoint"), which will eventually be replaced with a different value.
                    // TODO: If this Resource ID ceases to work, check for an updated value at http://go.microsoft.com/fwlink/?LinkID=392944
                    ResourceId = "Microsoft.SharePoint",

                    ApiEndpoint = "https://api.office.com/discovery/me"
                };

                info.AccessToken = await Office365Helper.GetAccessToken(info.ResourceId);

                return(info);
            }
Пример #4
0
            internal async static Task <Office365ServiceInfo> CreateAsync()
            {
                // Attempt to build an Office365ServiceInfo object based on cached API endpoint & resource ID information:
                Office365ServiceInfo info = new SharePointOneDriveServiceInfo()
                {
                    ResourceId  = (string)Office365Helper.GetFromCache("SharePointOneDriveResourceId"),
                    ApiEndpoint = (string)Office365Helper.GetFromCache("SharePointOneDriveApiEndpoint")
                };

                // If the cached Resource ID and API Endpoint are not empty, then use them:
                if ((info.ResourceId != null) && (info.ApiEndpoint != null))
                {
                    info.AccessToken = await Office365Helper.GetAccessToken(info.ResourceId);

                    return(info);
                }

                // If did not return above, invoke the Discovery Service to obtain the resource ID and API endpoint:
                DiscoveryServiceInfo discoveryServiceInfo = await DiscoveryServiceInfo.CreateAsync();

                if (!discoveryServiceInfo.HasValidAccessToken)
                {
                    // Cannot communicated with Service Discovery, so return the empty SharePointOneDriveServiceInfo as is.
                    //     The missing access token will let the caller know that the service is not ready to be used.
                    return(info);
                }

                DiscoveryResult[] results = await discoveryServiceInfo.DiscoverServicesAsync();

                DiscoveryResult myFilesEndpoint = results.First(result => result.Capability == "MyFiles");

                // Update and cache the resource ID and API endpoint:
                info.ResourceId = myFilesEndpoint.ServiceResourceId;
                // NOTE: In the initial Preview release of Service Discovery, the "MyFiles" endpoint URL will always
                //     start with something like "https://contoso-my.sharepoint.com/personal/<username>_contoso_com/_api",
                //     but the path following "/_api" may change over time.  For consistency, it is safer to manually
                //     extract the root path, and then append a call for the location of the Documents folder:
                info.ApiEndpoint = myFilesEndpoint.ServiceEndpointUri.Substring(
                    0, myFilesEndpoint.ServiceEndpointUri.IndexOf("/_api", StringComparison.Ordinal)) +
                                   "/_api/web/getfolderbyserverrelativeurl('Documents')";
                Office365Helper.SaveInCache("SharePointOneDriveResourceId", info.ResourceId);
                Office365Helper.SaveInCache("SharePointOneDriveApiEndpoint", info.ApiEndpoint);
                info.AccessToken = await Office365Helper.GetAccessToken(info.ResourceId);

                return(info);
            }