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

Updated dependencies #408

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.2.0 (unrelease)

### Improved

- Updated Dependencies (AWS, Box, Dropbox, Google Drive, Google Storage, OneDrive)
- Using .Net 4.8 now

## 2.1.0 (2024-06-17)

### New
Expand Down
12 changes: 10 additions & 2 deletions KeeAnywhere.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeeAnywhere", "KeeAnywhere\KeeAnywhere.csproj", "{8E40EDF5-06B8-4059-8B19-CB90D937FEBB}"
EndProject
Expand All @@ -25,6 +25,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{4CC0AA8D-734
version_manifest.txt = version_manifest.txt
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Chocolatey", "Chocolatey", "{93E4E5BD-9206-4479-AC34-BEDDD9D37DC9}"
ProjectSection(SolutionItems) = preProject
chocolatey\keepass-plugin-keeanywhere.nuspec = chocolatey\keepass-plugin-keeanywhere.nuspec
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,4 +44,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {79A52A20-6395-4845-937E-CCFD13C162E0}
EndGlobalSection
EndGlobal
333 changes: 199 additions & 134 deletions KeeAnywhere/KeeAnywhere.csproj

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion KeeAnywhere/KeeAnywhereExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,15 @@ private static void FixDependencyLoading()
"Microsoft.Graph.Core",
"Google.Apis",
"Google.Apis.Auth",
"Google.Apis.Core"
"Google.Apis.Core",
"Microsoft.Kiota.Abstractions",
"Microsoft.Bcl.AsyncInterfaces",
"System.Diagnostics.DiagnosticSource",
"System.Text.Json",
"System.Text.Encodings.Web",
"System.Runtime.CompilerServices.Unsafe",
"Microsoft.Extensions.Logging.Abstractions",
"System.Net.Http.WinHttpHandler"
// "System.Text.Encodings.Web",
// "System.Runtime.CompilerServices.Unsafe"
};
Expand Down
4 changes: 2 additions & 2 deletions KeeAnywhere/OAuth2/OidcFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ private OidcClientOptions CreateBaseOptions()
ClientId = m_clientId,
ClientSecret = m_clientSecret,
Scope = scopes,
Flow = OidcClientOptions.AuthenticationFlow.AuthorizationCode,
ResponseMode = OidcClientOptions.AuthorizeResponseMode.FormPost,
//Flow = OidcClientOptions.AuthenticationFlow.AuthorizationCode,
//ResponseMode = OidcClientOptions.AuthorizeResponseMode.FormPost,
RefreshTokenInnerHttpHandler = ProxyTools.CreateHttpClientHandler(),
BackchannelHandler = ProxyTools.CreateHttpClientHandler(),
LoadProfile = false
Expand Down
14 changes: 7 additions & 7 deletions KeeAnywhere/OAuth2/OidcSystemBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ public async Task<BrowserResult> InvokeAsync(BrowserOptions options, Cancellatio

string result;

if (options.ResponseMode == IdentityModel.OidcClient.OidcClientOptions.AuthorizeResponseMode.Redirect)
{
//if (options.ResponseMode == IdentityModel.OidcClient.OidcClientOptions.AuthorizeResponseMode.Redirect)
//{
result = context.Request.Url.Query;
}
else
{
result = ProcessFormPost(context.Request);
}
//}
//else
//{
// result = ProcessFormPost(context.Request);
//}

await SendResponse(context.Response);

Expand Down
8 changes: 4 additions & 4 deletions KeeAnywhere/PluginResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion KeeAnywhere/StorageProviders/Box/BoxStorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task<Stream> Load(string path)
if (item == null)
return null;

var stream = await api.FilesManager.DownloadStreamAsync(item.Id);
var stream = await api.FilesManager.DownloadAsync(item.Id);

return stream;
}
Expand Down
13 changes: 9 additions & 4 deletions KeeAnywhere/StorageProviders/OneDrive/OneDriveApiExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Graph;
using Microsoft.Graph.Drives.Item.Items.Item;
using System;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -18,7 +19,7 @@ public static class OneDriveApiExtensions
/// by the OneDrive storage provider.
/// </param>
/// <returns></returns>
public static IDriveItemRequestBuilder DriveItemFromStorageProviderItemId(this IGraphServiceClient api, string itemId)
public static DriveItemItemRequestBuilder DriveItemFromStorageProviderItemId(this GraphServiceClient api, string itemId)
{
// ID must include a drive id prefix.
// See also OneDriveStorageProvider.MakeStorageProviderItemId.
Expand All @@ -43,18 +44,22 @@ public static IDriveItemRequestBuilder DriveItemFromStorageProviderItemId(this I
/// An extra Web request has to be made to determine if the top
/// folder is remote or local. That's why this method is async.
/// </remarks>
public async static Task<IDriveItemRequestBuilder> DriveItemFromPathAsync(this IGraphServiceClient api, string path)
public async static Task<DriveItemItemRequestBuilder> DriveItemFromPathAsync(this GraphServiceClient api, string path)
{
// The top folder could be a shared folder, in which case it's
// on a different drive than the default. The path will use the
// name of the link in the user's root, which may be different
// from its actual (remote) name.
if (string.IsNullOrEmpty(path)) throw new ArgumentOutOfRangeException("path");
var parts = path.Split('/');
var rootItem = await api.Me.Drive.GetAsync();

if (parts.Length == 1)
return api.Drive.Root.ItemWithPath(parts[0]);
{
return api.Drives[rootItem.Id].Root.ItemWithPath(parts[0]);
}

var topFolder = await api.Drive.Root.ItemWithPath(Uri.EscapeDataString(parts[0])).Request().GetAsync();
var topFolder = await api.Drives[rootItem.Id].Root.ItemWithPath(Uri.EscapeDataString(parts[0])).GetAsync();
var driveId = topFolder.RemoteItem == null ? topFolder.ParentReference.DriveId : topFolder.RemoteItem.ParentReference.DriveId;
var topFolderId = topFolder.RemoteItem == null ? topFolder.Id : topFolder.RemoteItem.Id;
// The top folder's apparent name can be different from its
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using IdentityModel.OidcClient.Results;
using KeeAnywhere.OAuth2;
using Microsoft.Graph;
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Abstractions.Authentication;

namespace KeeAnywhere.StorageProviders.OneDrive
{
Expand All @@ -20,7 +24,7 @@ public OneDriveAuthenticationProvider(OidcFlow flow, string refreshToken)
_refreshToken = refreshToken;
}

public async Task AuthenticateRequestAsync(HttpRequestMessage request)
public async Task AuthenticateRequestAsync(RequestInformation request, Dictionary<string, object> additionalAuthenticationContext = null, CancellationToken cancellationToken = default(CancellationToken))
{
var token = _token;

Expand All @@ -31,12 +35,7 @@ public async Task AuthenticateRequestAsync(HttpRequestMessage request)
if (token.IsError)
{
_token = null;
throw new ServiceException(
new Error
{
//Code = GraphErrorCode.AuthenticationFailure,
Message = _token.Error
});
throw new ServiceException(_token.Error);
}

_token = token;
Expand All @@ -45,7 +44,7 @@ public async Task AuthenticateRequestAsync(HttpRequestMessage request)
var accessToken = token.AccessToken;
if (!string.IsNullOrEmpty(accessToken))
{
request.Headers.Authorization = new AuthenticationHeaderValue(CoreConstants.Headers.Bearer, accessToken);
request.Headers.Add("Authorization", new AuthenticationHeaderValue(CoreConstants.Headers.Bearer, accessToken).ToString());
}
}
}
Expand Down
23 changes: 16 additions & 7 deletions KeeAnywhere/StorageProviders/OneDrive/OneDriveHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using IdentityModel;
using KeeAnywhere.Configuration;
using KeeAnywhere.OAuth2;
Expand Down Expand Up @@ -35,7 +37,7 @@ never the real production keys.
"Files.ReadWrite"
};

private static readonly IDictionary<string, IGraphServiceClient> Cache = new Dictionary<string, IGraphServiceClient>();
private static readonly IDictionary<string, GraphServiceClient> Cache = new Dictionary<string, GraphServiceClient>();

public static OidcFlow CreateOidcFlow()
{
Expand All @@ -45,18 +47,25 @@ public static OidcFlow CreateOidcFlow()
};
}

public static IGraphServiceClient GetApi(AccountConfiguration account)
public static GraphServiceClient GetApi(AccountConfiguration account)
{
if (Cache.ContainsKey(account.Id)) return Cache[account.Id];

var authProvider = new OneDriveAuthenticationProvider(CreateOidcFlow(), account.Secret);

var httpProvider = new HttpProvider(ProxyTools.CreateHttpClientHandler(), true)
{
OverallTimeout = Timeout.InfiniteTimeSpan
};
//var httpProvider = new HttpProvider(ProxyTools.CreateHttpClientHandler(), true)
//{
// OverallTimeout = Timeout.InfiniteTimeSpan
//};

//var api = new GraphServiceClient(authProvider, httpProvider);
//var api = new GraphServiceClient(ProxyTools.CreateHttpClient(), authProvider);
//var api = new GraphServiceClient(authProvider);

var handlers = GraphClientFactory.CreateDefaultHandlers();
var httpClient = GraphClientFactory.Create(handlers, "v1.0", "Global", ProxyTools.GetProxy());
var api = new GraphServiceClient(httpClient, authProvider);

var api = new GraphServiceClient(authProvider, httpProvider);
Cache.Add(account.Id, api);

return api;
Expand Down
33 changes: 19 additions & 14 deletions KeeAnywhere/StorageProviders/OneDrive/OneDriveStorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
using System.Threading.Tasks;
using KeeAnywhere.Configuration;
using Microsoft.Graph;
using Microsoft.Graph.Drives.Item.Items.Item.Copy;
using Microsoft.Graph.Models;

namespace KeeAnywhere.StorageProviders.OneDrive
{
public class OneDriveStorageProvider : IStorageProvider
{
private readonly AccountConfiguration _account;
private readonly IGraphServiceClient _api;
private readonly GraphServiceClient _api;

public OneDriveStorageProvider(AccountConfiguration account)
{
Expand All @@ -24,7 +26,6 @@ public async Task<Stream> Load(string path)
{
var stream = await (await _api.DriveItemFromPathAsync(path))
.Content
.Request()
.GetAsync();

return stream;
Expand All @@ -35,8 +36,7 @@ public async Task Save(Stream stream, string path)
{
var uploadedItem = await (await _api.DriveItemFromPathAsync(path))
.Content
.Request()
.PutAsync<DriveItem>(stream);
.PutAsync(stream);

if (uploadedItem == null)
throw new InvalidOperationException("Save to OneDrive failed.");
Expand All @@ -46,24 +46,29 @@ public async Task Save(Stream stream, string path)
public async Task Copy(string sourcePath, string destPath)
{
var destFilename = CloudPath.GetFileName(destPath);
var destItem = await (await _api.DriveItemFromPathAsync(destPath)).Request().GetAsync();
var destItem = await (await _api.DriveItemFromPathAsync(destPath)).GetAsync();
if (destItem == null)
throw new FileNotFoundException("OneDrive: Folder not found.", destPath);

var body = new CopyPostRequestBody
{
Name = destFilename,
ParentReference = new ItemReference { Id = destItem.Id }
};

await (await _api.DriveItemFromPathAsync(sourcePath))
.Copy(destFilename, new ItemReference {Id = destItem.Id})
.Request(/*new[] {new HeaderOption("Prefer", "respond-async"), }*/)
.PostAsync();
.Copy.PostAsync(body);
}

public async Task Delete(string path)
{
await (await _api.DriveItemFromPathAsync(path)).Request().DeleteAsync();
await (await _api.DriveItemFromPathAsync(path)).DeleteAsync();
}

public async Task<StorageProviderItem> GetRootItem()
{
var odItem = await _api.Drive.Root.Request().GetAsync();
var rootItem = await _api.Me.Drive.GetAsync();
var odItem = await _api.Drives[rootItem.Id].Root.GetAsync();

if (odItem == null)
return null;
Expand All @@ -83,19 +88,19 @@ public async Task<IEnumerable<StorageProviderItem>> GetChildrenByParentItem(Stor
{
if (parent == null) throw new ArgumentNullException("parent");

var odChildren = await _api.DriveItemFromStorageProviderItemId(parent.Id).Children.Request().GetAsync();
var odChildren = await _api.DriveItemFromStorageProviderItemId(parent.Id).Children.GetAsync();

var children =
odChildren.Select(odItem => CreateStorageProviderItemFromOneDriveItem(odItem)).ToArray();
odChildren.Value.Select(odItem => CreateStorageProviderItemFromOneDriveItem(odItem)).ToArray();

return children;
}

public async Task<IEnumerable<StorageProviderItem>> GetChildrenByParentPath(string path)
{
var odChildren = await (await _api.DriveItemFromPathAsync(path)).Children.Request().GetAsync();
var odChildren = await (await _api.DriveItemFromPathAsync(path)).Children.GetAsync();
var children =
odChildren.Select(odItem => CreateStorageProviderItemFromOneDriveItem(odItem)).ToArray();
odChildren.Value.Select(odItem => CreateStorageProviderItemFromOneDriveItem(odItem)).ToArray();

return children;
}
Expand Down
Loading