Skip to content

Commit a5f05a9

Browse files
Merge pull request #26 from easymorph/development/5.8.1
5.8.1
2 parents b0062eb + 07a3b95 commit a5f05a9

File tree

85 files changed

+2620
-572
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2620
-572
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using Morph.Server.Sdk.Dto;
2+
using Morph.Server.Sdk.Helper;
3+
using Morph.Server.Sdk.Model;
4+
using Morph.Server.Sdk.Model.InternalModels;
5+
using System;
6+
using System.Collections.Specialized;
7+
using System.Net.Http;
8+
9+
using System.Threading;
10+
using System.Threading.Tasks;
11+
12+
namespace Morph.Server.Sdk.Client
13+
{
14+
internal static class AdSeamlessIdPAuthenticator
15+
{
16+
public static async Task<ApiSession> OpenSession(OpenSessionAuthenticatorContext context, string idPId, bool keepSignedId, CancellationToken cancellationToken)
17+
{
18+
if (context is null)
19+
{
20+
throw new ArgumentNullException(nameof(context));
21+
}
22+
23+
if (string.IsNullOrEmpty(idPId))
24+
{
25+
throw new ArgumentException($"'{nameof(idPId)}' cannot be null or empty.", nameof(idPId));
26+
}
27+
28+
29+
// handler will be disposed automatically
30+
using (HttpClientHandler aHandler = new HttpClientHandler()
31+
{
32+
ClientCertificateOptions = ClientCertificateOption.Automatic,
33+
// required for automatic NTML/Negotiate challenge
34+
UseDefaultCredentials = true,
35+
ServerCertificateCustomValidationCallback = context.MorphServerApiClient.Config.ServerCertificateCustomValidationCallback
36+
})
37+
{
38+
// build a new low level client based on specified handler
39+
using (var ntmlRestApiClient = context.BuildApiClient(aHandler))
40+
{
41+
var serverNonceApiResult = await context.LowLevelApiClient.AuthGenerateNonce(cancellationToken);
42+
serverNonceApiResult.ThrowIfFailed();
43+
var nonce = serverNonceApiResult.Data.Nonce;
44+
45+
var token = await internalAuthExternalWindowAsync(ntmlRestApiClient, nonce, idPId, keepSignedId, cancellationToken);
46+
47+
return ApiSessionFactory.CreatePersitableApiSession(token);
48+
}
49+
}
50+
}
51+
static async Task<string> internalAuthExternalWindowAsync(IRestClient apiClient, string serverNonce, string idPId, bool keepSignedIn, CancellationToken cancellationToken)
52+
{
53+
if (string.IsNullOrWhiteSpace(idPId))
54+
{
55+
throw new ArgumentException($"'{nameof(idPId)}' cannot be null or whitespace.", nameof(idPId));
56+
}
57+
58+
var url = UrlHelper.JoinUrl("auth", "external", "windows", idPId);
59+
var requestDto = new AdSeamlessIdPSigninRequestDto
60+
{
61+
RequestToken = serverNonce
62+
};
63+
64+
var ulrParameters = new NameValueCollection
65+
{
66+
{"keepSignedIn", keepSignedIn.ToString() }
67+
};
68+
var apiResult = await apiClient.PostAsync<AdSeamlessIdPSigninRequestDto, LoginResponseDto>(url, requestDto, ulrParameters, new HeadersCollection(), cancellationToken);
69+
apiResult.ThrowIfFailed();
70+
return apiResult.Data.Token;
71+
72+
}
73+
}
74+
}
75+
76+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Threading;
3+
4+
namespace Morph.Server.Sdk.Client
5+
{
6+
/// <summary>
7+
/// Provides one-per-AppDomain session refresher to be used as sensible default/fallback refresher
8+
/// </summary>
9+
internal static class AppWideLegacyApiSessionRefresher
10+
{
11+
private static readonly Lazy<LegacyApiSessionRefresher> Provider = new Lazy<LegacyApiSessionRefresher>(
12+
() => new LegacyApiSessionRefresher(),
13+
LazyThreadSafetyMode.ExecutionAndPublication);
14+
15+
public static LegacyApiSessionRefresher Instance => Provider.Value;
16+
}
17+
}

src/Client/AppWideSessionRefresher.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Client/DataTransferUtility.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ public class DataTransferUtility : IDataTransferUtility
1414
private int BufferSize { get; set; } = 81920;
1515
private readonly IMorphServerApiClient _morphServerApiClient;
1616
private readonly ApiSession _apiSession;
17+
private readonly string _spaceName;
1718

18-
public DataTransferUtility(IMorphServerApiClient morphServerApiClient, ApiSession apiSession)
19+
public DataTransferUtility(IMorphServerApiClient morphServerApiClient, ApiSession apiSession, string spaceName)
1920
{
21+
if (string.IsNullOrWhiteSpace(spaceName))
22+
{
23+
throw new ArgumentException($"'{nameof(spaceName)}' cannot be null or whitespace.", nameof(spaceName));
24+
}
25+
2026
this._morphServerApiClient = morphServerApiClient ?? throw new ArgumentNullException(nameof(morphServerApiClient));
2127
this._apiSession = apiSession ?? throw new ArgumentNullException(nameof(apiSession));
28+
this._spaceName = spaceName;
2229
}
2330

2431
public async Task SpaceUploadFileAsync(string localFilePath, string serverFolder, CancellationToken cancellationToken, bool overwriteExistingFile = false)
@@ -39,7 +46,7 @@ public async Task SpaceUploadFileAsync(string localFilePath, string serverFolder
3946
OverwriteExistingFile = overwriteExistingFile,
4047
ServerFolder = serverFolder
4148
};
42-
await _morphServerApiClient.SpaceUploadDataStreamAsync(_apiSession, request, cancellationToken);
49+
await _morphServerApiClient.SpaceUploadDataStreamAsync(_apiSession, _spaceName, request, cancellationToken);
4350
return;
4451
}
4552
}
@@ -73,7 +80,7 @@ public async Task SpaceDownloadFileIntoFileAsync(string remoteFilePath, string t
7380
{
7481
using (Stream tempFileStream = File.Open(tempFile, FileMode.Create))
7582
{
76-
using (var serverStreamingData = await _morphServerApiClient.SpaceOpenStreamingDataAsync(_apiSession, remoteFilePath, cancellationToken))
83+
using (var serverStreamingData = await _morphServerApiClient.SpaceOpenStreamingDataAsync(_apiSession, _spaceName, remoteFilePath, cancellationToken))
7784
{
7885
await serverStreamingData.Stream.CopyToAsync(tempFileStream, BufferSize, cancellationToken);
7986
}
@@ -116,7 +123,7 @@ public async Task SpaceDownloadFileIntoFolderAsync(string remoteFilePath, string
116123
using (Stream tempFileStream = File.Open(tempFile, FileMode.Create))
117124
{
118125

119-
using (var serverStreamingData = await _morphServerApiClient.SpaceOpenStreamingDataAsync(_apiSession, remoteFilePath, cancellationToken))
126+
using (var serverStreamingData = await _morphServerApiClient.SpaceOpenStreamingDataAsync(_apiSession, _spaceName, remoteFilePath, cancellationToken))
120127
{
121128
destFileName = Path.Combine(targetLocalFolder, serverStreamingData.FileName);
122129

@@ -166,7 +173,7 @@ public async Task SpaceUploadFileAsync(string localFilePath, string serverFolder
166173
OverwriteExistingFile = overwriteExistingFile,
167174
ServerFolder = serverFolder
168175
};
169-
await _morphServerApiClient.SpaceUploadDataStreamAsync(_apiSession, request, cancellationToken);
176+
await _morphServerApiClient.SpaceUploadDataStreamAsync(_apiSession, _spaceName, request, cancellationToken);
170177
return;
171178
}
172179
}

src/Client/IApiSessionRefresher.cs renamed to src/Client/ILegacyApiSessionRefresher.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Net.Http;
1+
using System;
2+
using System.Net.Http;
23
using System.Threading;
34
using System.Threading.Tasks;
45
using Morph.Server.Sdk.Model;
@@ -15,7 +16,7 @@ namespace Morph.Server.Sdk.Client
1516
/// <summary>
1617
/// Service that provides seamless API token refresh
1718
/// </summary>
18-
public interface IApiSessionRefresher
19+
public interface ILegacyApiSessionRefresher
1920
{
2021
/// <summary>
2122
/// Re-authenticates current session (if any) and seamlessly updates existing <see cref="ApiSession"/> instances that were associated
@@ -28,11 +29,11 @@ public interface IApiSessionRefresher
2829

2930
/// <summary>
3031
/// Save <see cref="authenticator"/> for <see cref="session"/>. T
31-
/// his is required for <see cref="ApiSession"/> object tracking and for <see cref="RefreshSessionAsync"/> to work.
32+
/// his is required for <see cref="LegacyApiSession"/> object tracking and for <see cref="RefreshSessionAsync"/> to work.
3233
/// </summary>
3334
/// <param name="session"></param>
3435
/// <param name="authenticator"></param>
35-
void AssociateAuthenticator(ApiSession session, Authenticator authenticator);
36+
void AssociateAuthenticator(LegacyApiSession session, Authenticator authenticator);
3637

3738
/// <summary>
3839
/// Returns true if <see cref="response"/> indicates that the session has expired

0 commit comments

Comments
 (0)