Reputation: 389
I have a VB.NET VS2012 project where I am successfully authenticating with the OneDrive folders using Azure AD. I want to be able to cache the credentials so I dont need to manually log in each time. The SDK hints at the possibility of caching credentials but I am not very familiar with the new OneDrive SDK so looking for some assistance on how I use the ADALCredentialCache object to store my login information. Before I can do that though, I need to work out how to connect to Azure AD with the extra parameters.
I am successfully connecting using the following statement and parameters which is using the discovery service.
var oneDriveClient = BusinessClientExtensions.GetActiveDirectoryClient(clientId, returnUrl);
I presume I need to connect using OneDrive for Business API endpoint and resource ID with the following command because I then should be able to use the CredentialCache parameter.
var oneDriveClient = BusinessClientExtensions.GetActiveDirectoryClient(
clientId,
returnUrl,
oneDriveApiEndpoint,
serviceResourceId)
My issue with this is that I have no idea what the serviceResourceId refers to. Can anyone shed any light please?
So that is the first part, the next part is how does one use the CredentialCache parameter to store and save the login credentials.
Any help would be much appreciated, I have already spent several days trawling the internet for answers but to date have not found anything concrete enough to provide the answers I need.
Cheers
Greg J
EDIT:
OK, now I am authenticating with the required command to use the credential cache I either have it wrong or I have the wrong idea on what it does. What I am trying to do is have subsequent calls to the app automatically authenticated. here is my code...
'Microsoft.OneDrive.Sdk.AdalCredentialCache
Dim credentialCache As AdalCredentialCache
If IO.File.Exists(strCacheFile) Then
Dim rcb As Byte() = IO.File.ReadAllBytes(strCacheFile)
credentialCache = New AdalCredentialCache(rcb)
Else
credentialCache = New AdalCredentialCache
End If
odc = BusinessClientExtensions.GetActiveDirectoryClient(azure_client_id, redirurl, sResource, endpoint_Url, credentialCache)
Await odc.AuthenticateAsync()
Dim ccb As Byte() = credentialCache.GetCacheBlob()
IO.File.WriteAllBytes(strCacheFile, ccb)
on the first pass I am prompted to enter my credentials so that is done and I connect. the cache is written to a file. On a subsequent call I get the cache info from the file and pass it to the credential cache variable, but I am still prompted to log in. The credentialCache has a length of 3582.
Any help would be appreciated.
Regards
Greg J
Upvotes: 0
Views: 268
Reputation: 277
serviceResourceId and oneDriveApiEndpoint are retrieved from Discovery service when you call BusinessClientExtensions.GetActiveDirectoryClient. See https://dev.onedrive.com/auth/aad_oauth.htm (Step 3 - Discover the OneDrive for Business resource URI) for more detailed explanation how discovery works and when it is executed.
For CredentialCache , AdalCredentialCache class can be used.
Upvotes: 1