Skip to content

Authentication Failed Error on Share with RequireLogin Set to True #58

Description

@shaistasohail

We have been using ShareFile SDK for a while now for creating folders, uploading and downloading files etc. and everything has been working fine. Until now when we created the share, it's RequireLogin attribute was set to false as shown below.

        var share = new Share
        {
            Items = new List<Item>
            {
                uploadedFile
            },
            ExpirationDate = DateTime.Now.AddYears(100),
            RequireLogin = false,
            RequireUserInfo = false
        };

Recently, we are required to secure the share so we set RequireLogin = true while creating the share. The upload and share creation still works fine. However, now when we try to download the file, we get the error "Authentication failed with status code: 401" when getting the share details. We have already authenticated, obtained a token and established a session. The download code is give below. We will appreciate if someone can help us understand the issue and changes we need to make to the code. Thanks in advance for your help!!

    /// <summary>
    /// 
    /// </summary>
    /// <param name="fileShare"></param>
    /// <returns></returns>
    public async Task<DownloadedItem> Download(string fileShare)
    {
        if (!sessionStarted)
            // Start a sharefile session.
            await StartSession();

        // Get the file share info
        Uri shareLink = new Uri(fileShare);
        string shareId = GetSharedId(fileShare);

        string shareUrl = $"https://{sfUser.Subdomain}.{sfUser.ControlPlane}/sf/v3/Shares({shareId})";
        Uri shareUri = new Uri(shareUrl);

//==> ERROR OCCURS ON THE NEXT LINE
var share = await sfClient.Shares.Get(shareUri).ExecuteAsync();

        DownloadedItem item = new DownloadedItem()
        {
            FileName = share.Title
        };

        // Download the file to a memory stream and return as byte array.
        var fileStream = await sfClient.Shares.Download(shareUri).ExecuteAsync();

        using (MemoryStream tempStream = new MemoryStream())
        {
            fileStream.CopyTo(tempStream);
            item.Content = tempStream.ToArray();
        }

        return item;
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions