I play with OneDrive SDK 1.1.15.0:
try
{
AppConfig appConfig = new AppConfig
{
MicrosoftAccountAppId = oneDriveClientID,
MicrosoftAccountClientSecret = oneDriveClientSecret,
MicrosoftAccountReturnUrl = "https://localhost/return",
MicrosoftAccountScopes = new string[] { "wl.signin", "wl.offline_access", "onedrive.readonly" }
};
OneDriveClient oneDriveClient = new OneDriveClient(appConfig);
AccountSession accountSession = await oneDriveClient.AuthenticateAsync();
await oneDriveClient.SignOutAsync();
}
catch (Exception ex)
{
throw ex;
}
My problem is in the line:
AccountSession accountSession = await oneDriveClient.AuthenticateAsync();
which raises the following exception:
Microsoft.OneDrive.Sdk.OneDriveException, AuthenticationFailure: Failed to retrieve a valid authentication token for the user.
Any ideas?
Thank you in advance!
UPDATE
After reading the comment from ginach (thanks!), I am updating my code. Some arguments emphasize:
- I want to access OneDrive from the Azure working role, so there are no authentication windows or anything like that.
- I am downloading the Microsoft.OneDrive SDK version in version 1.1.20.
- I have already registered my application on the OneDrive dev portal.
My actual code is:
try
{
MicrosoftAccountServiceInfo serviceInfo = new MicrosoftAccountServiceInfo();
serviceInfo.AppId = oneDriveClientID;
serviceInfo.ClientSecret = oneDriveClientSecret;
serviceInfo.ReturnUrl = oneDriveReturnUrl;
serviceInfo.Scopes = oneDriveAccountScopes;
MicrosoftAccountAuthenticationProvider authenticationProvider = new MicrosoftAccountAuthenticationProvider(serviceInfo);
OneDriveClient oneDriveClient = await OneDriveClient.GetAuthenticatedMicrosoftAccountClient(oneDriveClientID, oneDriveReturnUrl, oneDriveAccountScopes, authenticationProvider);
await oneDriveClient.SignOutAsync();
}
catch (OneDriveException odex)
{
throw odex;
}
catch (Exception ex)
{
throw ex;
}
I get again and again (in the OneDriveClient.GetAuthenticatedMicrosoftAccountClient method). OneDriveException (Error property): AuthenticationFailure - Failed to get a valid authentication token for the user.
Any suggestion?
Thanks.
UPDATE 2
, . RestSharp, OneDrive :
string clientId = "00[...]00";
string scopes = "wl.signin, wl.offline_access, onedrive.readonly";
string responseType = "code";
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
RestClient client = new RestClient("https://login.live.com");
RestRequest request = new RestRequest();
request.Method = Method.GET;
request.Resource = "oauth20_authorize.srf";
request.AddQueryParameter("client_id", clientId);
request.AddQueryParameter("scope", scopes);
request.AddQueryParameter("response_type", responseType);
request.AddQueryParameter("redirect_uri", redirectUri);
IRestResponse response = client.Execute(request);
string content = response.Content;
Fiddler, , , :
https://login.live.com/oauth20_authorize.srf?client_id=00[...]00&scope=wl.signin%20wl.offline_access%20onedrive.readonly&response_type=code&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf
OneDrive :
Microsoft JavaScript. - JavaScript, . , JavaScript , .
, , OneDrive :

: - , ?
,