Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always need to sign in again and again to oneDrive. Session not saved? #4

Open
Txusete opened this issue Oct 28, 2016 · 0 comments
Open

Comments

@Txusete
Copy link

Txusete commented Oct 28, 2016

Hi,

I'm successfully connecting to OneDrive from a c# application on a consumer ClientType mode. However i always need to accept the "terms and conditions" when i start the application.
i'm using the following code (provided on the OneDriveApiBrowser):

private async Task SignIn(ClientType clientType)
{
Task authTask;

        if (clientType == ClientType.Consumer)
        {
            var msaAuthProvider = new MsaAuthenticationProvider(
                FormBrowser.MsaClientId,
                null,
                FormBrowser.MsaReturnUrl,
                FormBrowser.Scopes,
                null,
                new CredentialVault(FormBrowser.MsaClientId));
            this.oneDriveClient = new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthProvider);
            authTask = msaAuthProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync();
        }
        else
        {
            var adalAuthProvider = new AdalAuthenticationProvider(
                FormBrowser.AadClientId,
                FormBrowser.AadReturnUrl);
            this.oneDriveClient = new OneDriveClient(FormBrowser.AadTargetUrl + "/_api/v2.0", adalAuthProvider);
            authTask = adalAuthProvider.AuthenticateUserAsync(FormBrowser.AadTargetUrl);
        }

        try
        {
            await authTask;
        }
        catch (ServiceException exception)
        {
            if (OAuthConstants.ErrorCodes.AuthenticationFailure == exception.Error.Code)
            {
                MessageBox.Show(
                    "Authentication failed",
                    "Authentication failed",
                    MessageBoxButtons.OK);

                this.oneDriveClient = null;
            }
            else
            {
                PresentServiceException(exception);
            }
        }

        this.clientType = clientType;

        try
        {
            await LoadFolderFromPath();

            UpdateConnectedStateUx(true);
        }
        catch (ServiceException exception)
        {
            PresentServiceException(exception);
            this.oneDriveClient = null;
        }
    }

I have been browsing all around the web and some people seem to have found a solution by using:
OneDriveClient.GetMicrosoftAccountClient(). thats also mentioned on the main page of this project , however the sample sources do not include that code anywhere. When i try to use that call on the project i got an error saying that OneDriveClient do not have a reference to GetMicrosoftAccountClient().

Is the sample not updated with the latests comments from the main page of the project?

Thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant