Skip to content

Commit ea928ac

Browse files
committed
7.3.0 release
1 parent d08e984 commit ea928ac

File tree

6 files changed

+27
-152
lines changed

6 files changed

+27
-152
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"ImageFileBase64": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=",
3-
"SubscriptionNotificationUrl": "https://prod-12.japaneast.logic.azure.com:443/workflows/890b7cade2aa4abfa5c9dd88ed174a1f/triggers/Request/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2FRequest%2Frun&sv=1.0&sig=Gws_hyjPOf-NMRBdAvhVHeL5US1Zs6Ovc6PoT2TkTDA"
3+
"SubscriptionNotificationUrl": "https://prod-03.japaneast.logic.azure.com:443/workflows/63134f37628d4a9092f4c3d4966005ea/triggers/HTTP_Request/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2FHTTP_Request%2Frun&sv=1.0&sig=OFlCrrbK0DGPT1iHvV5cWX18jNCZi22JRHXKTBX0jIo"
44
}

source/Karamem0.SPClientCore/Commands/ConnectSiteCommand.cs

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -53,51 +53,39 @@ public class ConnectSiteCommand : OAuthCmdlet
5353
Position = 0,
5454
ValueFromPipeline = true
5555
)]
56-
[Parameter(
57-
Mandatory = true,
58-
ParameterSetName = "ParamSet6",
59-
Position = 0,
60-
ValueFromPipeline = true
61-
)]
6256
public Uri Url { get; private set; }
6357

58+
[Parameter(Mandatory = true, ParameterSetName = "ParamSet1")]
6459
[Parameter(Mandatory = true, ParameterSetName = "ParamSet2")]
65-
public PSCredential Credential { get; private set; }
66-
67-
[Parameter(Mandatory = false, ParameterSetName = "ParamSet1")]
68-
[Parameter(Mandatory = false, ParameterSetName = "ParamSet2")]
6960
[Parameter(Mandatory = true, ParameterSetName = "ParamSet3")]
7061
[Parameter(Mandatory = true, ParameterSetName = "ParamSet4")]
71-
[Parameter(Mandatory = false, ParameterSetName = "ParamSet5")]
72-
[Parameter(Mandatory = true, ParameterSetName = "ParamSet6")]
73-
public string ClientId { get; private set; } = OAuthConstants.ClientId;
62+
[Parameter(Mandatory = true, ParameterSetName = "ParamSet5")]
63+
public string ClientId { get; private set; }
7464

7565
[Parameter(Mandatory = false, ParameterSetName = "ParamSet1")]
7666
[Parameter(Mandatory = false, ParameterSetName = "ParamSet2")]
7767
[Parameter(Mandatory = false, ParameterSetName = "ParamSet3")]
7868
[Parameter(Mandatory = false, ParameterSetName = "ParamSet4")]
79-
[Parameter(Mandatory = false, ParameterSetName = "ParamSet5")]
8069
public Uri Authority { get; private set; } = new Uri(OAuthConstants.AadAuthority, UriKind.Absolute);
8170

8271
[Parameter(Mandatory = false, ParameterSetName = "ParamSet1")]
83-
[Parameter(Mandatory = false, ParameterSetName = "ParamSet2")]
8472
public SwitchParameter UserMode { get; private set; }
8573

74+
[Parameter(Mandatory = true, ParameterSetName = "ParamSet2")]
8675
[Parameter(Mandatory = true, ParameterSetName = "ParamSet3")]
87-
[Parameter(Mandatory = true, ParameterSetName = "ParamSet4")]
8876
public string CertificatePath { get; private set; }
8977

90-
[Parameter(Mandatory = true, ParameterSetName = "ParamSet3")]
78+
[Parameter(Mandatory = true, ParameterSetName = "ParamSet2")]
9179
public SecureString CertificatePassword { get; private set; }
9280

93-
[Parameter(Mandatory = true, ParameterSetName = "ParamSet4")]
81+
[Parameter(Mandatory = true, ParameterSetName = "ParamSet3")]
9482
public string PrivateKeyPath { get; private set; }
9583

96-
[Parameter(Mandatory = true, ParameterSetName = "ParamSet5")]
84+
[Parameter(Mandatory = true, ParameterSetName = "ParamSet4")]
9785
public SwitchParameter Cached { get; private set; }
9886

99-
[Parameter(Mandatory = true, ParameterSetName = "ParamSet6")]
100-
public string ClientSecret { get; private set; }
87+
[Parameter(Mandatory = true, ParameterSetName = "ParamSet5")]
88+
public SecureString ClientSecret { get; private set; }
10189

10290
protected override void ProcessRecordCore()
10391
{
@@ -113,19 +101,8 @@ protected override void ProcessRecordCore()
113101
}
114102
if (this.ParameterSetName == "ParamSet2")
115103
{
116-
this.Service.ConnectWithPassword(
117-
this.Authority,
118-
this.ClientId,
119-
this.Url,
120-
this.Credential.GetNetworkCredential(),
121-
this.UserMode
122-
);
123-
}
124-
if (this.ParameterSetName == "ParamSet3")
125-
{
126-
var certificatePath = this
127-
.SessionState.Path.GetResolvedPSPathFromPSPath(this.CertificatePath)[0];
128-
var certificateBytes = BinaryData.FromBytes(File.ReadAllBytes(Path.GetFullPath(certificatePath.Path)));
104+
var certificatePath = this.GetUnresolvedProviderPathFromPSPath(this.CertificatePath);
105+
var certificateBytes = BinaryData.FromBytes(File.ReadAllBytes(certificatePath));
129106
this.Service.ConnectWithCertificate(
130107
this.Authority,
131108
this.ClientId,
@@ -134,14 +111,12 @@ protected override void ProcessRecordCore()
134111
this.CertificatePassword
135112
);
136113
}
137-
if (this.ParameterSetName == "ParamSet4")
114+
if (this.ParameterSetName == "ParamSet3")
138115
{
139-
var certificatePath = this
140-
.SessionState.Path.GetResolvedPSPathFromPSPath(this.CertificatePath)[0];
141-
var certificateBytes = BinaryData.FromBytes(File.ReadAllBytes(Path.GetFullPath(certificatePath.Path)));
142-
var privateKeyPath = this
143-
.SessionState.Path.GetResolvedPSPathFromPSPath(this.PrivateKeyPath)[0];
144-
var privateKeyBytes = BinaryData.FromBytes(File.ReadAllBytes(Path.GetFullPath(privateKeyPath.Path)));
116+
var certificatePath = this.GetUnresolvedProviderPathFromPSPath(this.CertificatePath);
117+
var certificateBytes = BinaryData.FromBytes(File.ReadAllBytes(certificatePath));
118+
var privateKeyPath = this.GetUnresolvedProviderPathFromPSPath(this.PrivateKeyPath);
119+
var privateKeyBytes = BinaryData.FromBytes(File.ReadAllBytes(privateKeyPath));
145120
this.Service.ConnectWithCertificate(
146121
this.Authority,
147122
this.ClientId,
@@ -150,7 +125,7 @@ protected override void ProcessRecordCore()
150125
privateKeyBytes
151126
);
152127
}
153-
if (this.ParameterSetName == "ParamSet5")
128+
if (this.ParameterSetName == "ParamSet4")
154129
{
155130
this.ValidateSwitchParameter(nameof(this.Cached));
156131
this.Service.ConnectWithCache(
@@ -159,7 +134,7 @@ protected override void ProcessRecordCore()
159134
this.Url
160135
);
161136
}
162-
if (this.ParameterSetName == "ParamSet6")
137+
if (this.ParameterSetName == "ParamSet5")
163138
{
164139
this.Service.ConnectWithClientSecret(
165140
this.ClientId,

source/Karamem0.SPClientCore/Runtime/OAuth/AadOAuthContext.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -142,64 +142,6 @@ public class AadOAuthContext(
142142
}
143143
}
144144

145-
public OAuthMessage? AcquireTokenByPassword(string userName, string password)
146-
{
147-
var tenantId = this.tenantIdResolver.Resolve();
148-
var requestUrl = new Uri(this.authority, UriKind.Absolute)
149-
.ConcatPath(tenantId)
150-
.ConcatPath("oauth2/v2.0/token");
151-
var requertParameters = new Dictionary<string, object?>()
152-
{
153-
["grant_type"] = "password",
154-
["client_id"] = this.clientId,
155-
["username"] = userName,
156-
["password"] = password,
157-
["scope"] = this.userMode
158-
? string.Join(
159-
" ",
160-
[
161-
"offline_access",
162-
$"{OAuthConstants.ResourceId}/AllSites.Manage"
163-
]
164-
)
165-
: string.Join(
166-
" ",
167-
[
168-
"offline_access",
169-
$"{OAuthConstants.ResourceId}/AllSites.FullControl",
170-
$"{OAuthConstants.ResourceId}/TermStore.ReadWrite.All",
171-
$"{OAuthConstants.ResourceId}/User.Read.All"
172-
]
173-
)
174-
};
175-
var requestContent = UriQuery.Create(requertParameters);
176-
var requestMessage = new HttpRequestMessage(HttpMethod.Post, requestUrl)
177-
{
178-
Content = new StringContent(
179-
requestContent,
180-
Encoding.UTF8,
181-
"application/x-www-form-urlencoded"
182-
)
183-
};
184-
requestMessage.Headers.Add("Accept", "application/json");
185-
var responseMessage = this
186-
.HttpClient.SendAsync(requestMessage)
187-
.GetAwaiter()
188-
.GetResult();
189-
var responseContent = responseMessage
190-
.Content.ReadAsStringAsync()
191-
.GetAwaiter()
192-
.GetResult();
193-
if (responseMessage.IsSuccessStatusCode)
194-
{
195-
return JsonConvert.DeserializeObject<AadOAuthToken>(responseContent);
196-
}
197-
else
198-
{
199-
return JsonConvert.DeserializeObject<OAuthError>(responseContent);
200-
}
201-
}
202-
203145
public OAuthMessage? AcquireTokenByRefreshToken(string refreshToken)
204146
{
205147
var tenantId = this.tenantIdResolver.Resolve();

source/Karamem0.SPClientCore/Runtime/OAuth/AcsOAuthContext.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
using System;
1212
using System.Collections.Generic;
1313
using System.Linq;
14+
using System.Net;
1415
using System.Net.Http;
16+
using System.Security;
1517
using System.Text;
1618

1719
namespace Karamem0.SharePoint.PowerShell.Runtime.OAuth;
1820

1921
public class AcsOAuthContext(
2022
string clientId,
21-
string clientSecret,
23+
SecureString clientSecret,
2224
string resource
2325
) : OAuthContext
2426
{
2527

26-
private readonly string clientId = clientId;
27-
28-
private readonly string clientSecret = clientSecret;
28+
private readonly NetworkCredential credential = new(clientId, clientSecret);
2929

3030
private readonly string resource = resource;
3131

@@ -44,10 +44,10 @@ string resource
4444
"grant_type", "client_credentials"
4545
},
4646
{
47-
"client_id", $"{this.clientId}@{tenantId}"
47+
"client_id", $"{this.credential.UserName}@{tenantId}"
4848
},
4949
{
50-
"client_secret", this.clientSecret
50+
"client_secret", this.credential.Password
5151
},
5252
{
5353
"resource", $"{OAuthConstants.ResourceId}/{resourceId}@{tenantId}"

source/Karamem0.SPClientCore/Runtime/OAuth/OAuthConstants.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ public static class OAuthConstants
2020

2121
public const string AcsAuthority = "https://accounts.accesscontrol.windows.net";
2222

23-
public const string ClientId = "d329ccf1-98fe-483f-b616-23cc5a874743";
24-
2523
public const string ResourceId = "00000003-0000-0ff1-ce00-000000000000";
2624

2725
}

source/Karamem0.SPClientCore/Runtime/OAuth/OAuthService.cs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ void ConnectWithDeviceCode(
3030
Action<string> callback
3131
);
3232

33-
void ConnectWithPassword(
34-
Uri authority,
35-
string clientId,
36-
Uri resource,
37-
NetworkCredential credential,
38-
bool userMode
39-
);
40-
4133
void ConnectWithCertificate(
4234
Uri authority,
4335
string clientId,
@@ -62,7 +54,7 @@ Uri resource
6254

6355
void ConnectWithClientSecret(
6456
string clientId,
65-
string clientSecret,
57+
SecureString clientSecret,
6658
Uri resource
6759
);
6860

@@ -153,38 +145,6 @@ Action<string> callback
153145
}
154146
}
155147

156-
public void ConnectWithPassword(
157-
Uri authority,
158-
string clientId,
159-
Uri resource,
160-
NetworkCredential credential,
161-
bool userMode
162-
)
163-
{
164-
var oAuthContext = new AadOAuthContext(
165-
authority.GetAuthority(),
166-
clientId,
167-
resource.GetAuthority(),
168-
userMode
169-
);
170-
var oAuthMessage = oAuthContext.AcquireTokenByPassword(credential.UserName, credential.Password);
171-
if (oAuthMessage is AadOAuthToken oAuthToken)
172-
{
173-
AadOAuthTokenStore.Add(resource, oAuthToken);
174-
ClientService.Register(
175-
ClientContext.Create(
176-
resource,
177-
oAuthContext,
178-
oAuthToken
179-
)
180-
);
181-
}
182-
if (oAuthMessage is OAuthError oAuthError)
183-
{
184-
throw new InvalidOperationException(oAuthError.ErrorDescription);
185-
}
186-
}
187-
188148
public void ConnectWithCertificate(
189149
Uri authority,
190150
string clientId,
@@ -270,7 +230,7 @@ Uri resource
270230

271231
public void ConnectWithClientSecret(
272232
string clientId,
273-
string clientSecret,
233+
SecureString clientSecret,
274234
Uri resource
275235
)
276236
{

0 commit comments

Comments
 (0)