Example #1
0
        public string CreateShareableLink(string id, OneDriveLinkType linkType = OneDriveLinkType.Read)
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("access_token", AuthInfo.Token.access_token);

            string linkTypeValue;

            switch (linkType)
            {
            case OneDriveLinkType.Embed:
                linkTypeValue = "embed";
                break;

            default:
            case OneDriveLinkType.Read:
                linkTypeValue = "shared_read_link";
                break;

            case OneDriveLinkType.Edit:
                linkTypeValue = "shared_edit_link";
                break;
            }

            string response = SendRequest(HttpMethod.GET, $"https://apis.live.net/v5.0/{id}/{linkTypeValue}", args);

            OneDriveShareableLinkInfo shareableLinkInfo = JsonConvert.DeserializeObject <OneDriveShareableLinkInfo>(response);

            if (shareableLinkInfo != null)
            {
                return(shareableLinkInfo.link);
            }

            return(null);
        }
Example #2
0
        public string CreateShareableLink(string id, OneDriveLinkType linkType = OneDriveLinkType.Read)
        {
            string linkTypeValue;

            switch (linkType)
            {
            case OneDriveLinkType.Embed:
                linkTypeValue = "embed";
                break;

            default:
            case OneDriveLinkType.Read:
                linkTypeValue = "view";
                break;

            case OneDriveLinkType.Edit:
                linkTypeValue = "edit";
                break;
            }

            string json = JsonConvert.SerializeObject(new
            {
                type  = linkTypeValue,
                scope = "anonymous"
            });

            string response = SendRequest(HttpMethod.POST, $"https://graph.microsoft.com/v1.0/me/drive/items/{id}/createLink", json, RequestHelpers.ContentTypeJSON,
                                          headers: GetAuthHeaders());

            OneDrivePermission permissionInfo = JsonConvert.DeserializeObject <OneDrivePermission>(response);

            if (permissionInfo != null && permissionInfo.link != null)
            {
                return(permissionInfo.link.webUrl);
            }

            return(null);
        }
 /// <summary>
 /// Shares a OneDrive item by creating an anonymous link to the item
 /// </summary>
 /// <param name="item">The OneDrive item to share</param>
 /// <param name="linkType">Type of sharing to request</param>
 /// <param name="scope">Scope defining who has access to the shared item</param>
 /// <returns>OneDrivePermission entity representing the share or NULL if the operation fails</returns>
 public async Task <OneDrivePermission> ShareItem(OneDriveItem item, OneDriveLinkType linkType, OneDriveSharingScope scope)
 {
     return(await ShareItemInternal(string.Concat("drive/items/", item.Id, "/createLink"), linkType, scope));
 }
 /// <summary>
 /// Shares a OneDrive item by creating an anonymous link to the item
 /// </summary>
 /// <param name="itemPath">The path to the OneDrive item to share</param>
 /// <param name="linkType">Type of sharing to request</param>
 /// <param name="scope">Scope defining who has access to the shared item</param>
 /// <returns>OneDrivePermission entity representing the share or NULL if the operation fails</returns>
 public async Task <OneDrivePermission> ShareItem(string itemPath, OneDriveLinkType linkType, OneDriveSharingScope scope)
 {
     return(await ShareItemInternal(string.Concat("drive/root:/", itemPath, ":/createLink"), linkType, scope));
 }
Example #5
0
        public async Task <OneDrivePermission> ShareItemModified(string oneDriveRequestUrl, OneDriveLinkType linkType, OneDriveSharingScope scope)
        {
            OneDriveItem item = new OneDriveItem()
            {
                Id = oneDriveRequestUrl
            };

            return(await ShareItem(item, linkType, scope));
        }
Example #6
0
        public string CreateShareableLink(string id, OneDriveLinkType linkType = OneDriveLinkType.Read)
        {
            Dictionary<string, string> args = new Dictionary<string, string>();
            args.Add("access_token", AuthInfo.Token.access_token);

            string linkTypeValue;

            switch (linkType)
            {
                case OneDriveLinkType.Embed:
                    linkTypeValue = "embed";
                    break;
                default:
                case OneDriveLinkType.Read:
                    linkTypeValue = "shared_read_link";
                    break;
                case OneDriveLinkType.Edit:
                    linkTypeValue = "shared_edit_link";
                    break;
            }

            string url = CreateQuery(string.Format("https://apis.live.net/v5.0/{0}/{1}", id, linkTypeValue), args);

            string response = SendRequest(HttpMethod.GET, url);

            OneDriveShareableLinkInfo shareableLinkInfo = JsonConvert.DeserializeObject<OneDriveShareableLinkInfo>(response);

            if (shareableLinkInfo != null)
            {
                return shareableLinkInfo.link;
            }

            return null;
        }
 /// <summary>
 /// Changes permissions on a OneDrive item
 /// </summary>
 /// <param name="itemPath">The path to the OneDrive item to change the permission of</param>
 /// <param name="permissionType">Permission to set on the OneDrive item</param>
 /// <param name="permission">Permission object applied to the OneDrive item which needs its permissions changed</param>
 /// <returns>OneDrivePermissionResponse object representing the granted permission</returns>
 public async Task <OneDrivePermissionResponse> ChangePermission(string itemPath, OneDrivePermission permission, OneDriveLinkType permissionType)
 {
     return(await ChangePermission(itemPath, permission.Id, permissionType));
 }
        /// <summary>
        /// Changes permissions on a OneDrive item
        /// </summary>
        /// <param name="itemPath">The path to the OneDrive item to change the permission of</param>
        /// <param name="permissionType">Permission to set on the OneDrive item</param>
        /// <param name="permissionId">ID of the permission object applied to the OneDrive item which needs its permissions changed</param>
        /// <returns>OneDrivePermissionResponse object representing the granted permission</returns>
        public async Task <OneDrivePermissionResponse> ChangePermission(string itemPath, string permissionId, OneDriveLinkType permissionType)
        {
            var completeUrl = string.Concat(OneDriveApiBaseUrl, "drive/root:/", itemPath, ":/permissions/", permissionId);

            var result = await SendMessageReturnOneDriveItem <OneDrivePermissionResponse>("{ \"roles\": [ \"" + (permissionType == OneDriveLinkType.Edit ? "write" : "read") + "\" ] }", new HttpMethod("PATCH"), completeUrl, HttpStatusCode.OK);

            return(result);
        }
 /// <summary>
 /// Changes permissions on a OneDrive item
 /// </summary>
 /// <param name="item">The OneDrive item to change the permission of</param>
 /// <param name="permissionType">Permission to set on the OneDrive item</param>
 /// <param name="permission">Permission object applied to the OneDrive item which needs its permissions changed</param>
 /// <returns>OneDrivePermissionResponse object representing the granted permission</returns>
 public async Task <OneDrivePermissionResponse> ChangePermission(OneDriveItem item, OneDrivePermission permission, OneDriveLinkType permissionType)
 {
     return(await ChangePermission(item, permission.Id, permissionType));
 }
        /// <summary>
        /// Adds permissions to a OneDrive item
        /// </summary>
        /// <param name="itemPath">The path to the OneDrive item to add the permission to</param>
        /// <param name="requireSignin">Boolean to indicate if the user has to sign in before being able to access the OneDrive item</param>
        /// <param name="linkType">Indicates what type of access should be assigned to the invitees</param>
        /// <param name="emailAddresses">Array with e-mail addresses to receive access to the OneDrive item</param>
        /// <param name="sendInvitation">Send an e-mail to the invitees to inform them about having received permissions to the OneDrive item</param>
        /// <param name="sharingMessage">Custom message to add to the e-mail sent out to the invitees</param>
        /// <returns>Collection with OneDrivePermissionResponse objects representing the granted permissions</returns>
        public async Task <OneDriveCollectionResponse <OneDrivePermissionResponse> > AddPermission(string itemPath, bool requireSignin, bool sendInvitation, OneDriveLinkType linkType, string sharingMessage, string[] emailAddresses)
        {
            var permissionRequest = new OneDrivePermissionRequest
            {
                Message        = sharingMessage,
                RequireSignin  = requireSignin,
                SendInvitation = sendInvitation,
                Roles          = linkType == OneDriveLinkType.View ? new[] { "read" } : new[] { "write" }
            };

            var recipients = new List <OneDriveDriveRecipient>();

            foreach (var emailAddress in emailAddresses)
            {
                recipients.Add(new OneDriveDriveRecipient
                {
                    Email = emailAddress
                });
            }
            permissionRequest.Recipients = recipients.ToArray();

            return(await AddPermission(itemPath, permissionRequest));
        }
Example #11
0
        private async Task <OneDriveGetLinkResponse> CreateSharableLinkAync(OAuth2Settings oAuth2Settings,
                                                                            string imageId, OneDriveLinkType oneDriveLinkType)
        {
            var sharableLink       = OneDriveUri.AppendSegments("items", imageId, "createLink");
            var localBehaviour     = _oneDriveHttpBehaviour.ShallowClone();
            var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour);

            oauthHttpBehaviour.MakeCurrent();
            var body = new OneDriveGetLinkRequest();

            body.Scope = oneDriveLinkType == OneDriveLinkType.@public ? "anonymous" : "organization";
            body.Type  = "view";
            return(await sharableLink.PostAsync <OneDriveGetLinkResponse>(body));
        }