Skip to content

Commit 36abdaa

Browse files
committed
fix(Builders): Added fluent builders for the newly added authentications
Signed-off-by: Charles d'Avernas <[email protected]>
1 parent 52924df commit 36abdaa

24 files changed

+772
-180
lines changed

src/ServerlessWorkflow.Sdk.Builders/AuthenticationPolicyDefinitionBuilder.cs

+25
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ public virtual IBearerAuthenticationSchemeDefinitionBuilder Bearer()
5353
return builder;
5454
}
5555

56+
/// <inheritdoc/>
57+
public virtual ICertificateAuthenticationSchemeDefinitionBuilder Certificate()
58+
{
59+
var builder = new CertificateAuthenticationSchemeDefinitionBuilder();
60+
this.SchemeBuilder = builder;
61+
return builder;
62+
}
63+
64+
/// <inheritdoc/>
65+
public virtual IDigestAuthenticationSchemeDefinitionBuilder Digest()
66+
{
67+
var builder = new DigestAuthenticationSchemeDefinitionBuilder();
68+
this.SchemeBuilder = builder;
69+
return builder;
70+
}
71+
5672
/// <inheritdoc/>
5773
public virtual IOAuth2AuthenticationSchemeDefinitionBuilder OAuth2()
5874
{
@@ -61,6 +77,14 @@ public virtual IOAuth2AuthenticationSchemeDefinitionBuilder OAuth2()
6177
return builder;
6278
}
6379

80+
/// <inheritdoc/>
81+
public virtual IOpenIDConnectAuthenticationSchemeDefinitionBuilder OpenIDConnect()
82+
{
83+
var builder = new OpenIDConnectAuthenticationSchemeDefinitionBuilder();
84+
this.SchemeBuilder = builder;
85+
return builder;
86+
}
87+
6488
/// <inheritdoc/>
6589
public virtual AuthenticationPolicyDefinition Build()
6690
{
@@ -72,6 +96,7 @@ public virtual AuthenticationPolicyDefinition Build()
7296
Basic = scheme is BasicAuthenticationSchemeDefinition basic ? basic : null,
7397
Bearer = scheme is BearerAuthenticationSchemeDefinition bearer ? bearer : null,
7498
OAuth2 = scheme is OAuth2AuthenticationSchemeDefinition oauth2 ? oauth2 : null,
99+
Oidc = scheme is OpenIDConnectSchemeDefinition oidc ? oidc : null
75100
};
76101
}
77102

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Represents the default implementation of the <see cref="ICertificateAuthenticationSchemeDefinitionBuilder"/> interface
18+
/// </summary>
19+
public class CertificateAuthenticationSchemeDefinitionBuilder
20+
: AuthenticationSchemeDefinitionBuilder<CertificateAuthenticationSchemeDefinition>, ICertificateAuthenticationSchemeDefinitionBuilder
21+
{
22+
23+
/// <inheritdoc/>
24+
public override CertificateAuthenticationSchemeDefinition Build()
25+
{
26+
return new()
27+
{
28+
Use = this.Secret
29+
};
30+
}
31+
32+
AuthenticationSchemeDefinition IAuthenticationSchemeDefinitionBuilder.Build() => this.Build();
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Represents the default implementation of the <see cref="IDigestAuthenticationSchemeDefinitionBuilder"/> interface
18+
/// </summary>
19+
public class DigestAuthenticationSchemeDefinitionBuilder
20+
: AuthenticationSchemeDefinitionBuilder<DigestAuthenticationSchemeDefinition>, IDigestAuthenticationSchemeDefinitionBuilder
21+
{
22+
23+
/// <summary>
24+
/// Gets/sets the username to use
25+
/// </summary>
26+
protected string? Username { get; set; }
27+
28+
/// <summary>
29+
/// Gets/sets the password to use
30+
/// </summary>
31+
protected string? Password { get; set; }
32+
33+
/// <inheritdoc/>
34+
public virtual IDigestAuthenticationSchemeDefinitionBuilder WithUsername(string username)
35+
{
36+
ArgumentException.ThrowIfNullOrWhiteSpace(username);
37+
this.Username = username;
38+
return this;
39+
}
40+
41+
/// <inheritdoc/>
42+
public virtual IDigestAuthenticationSchemeDefinitionBuilder WithPassword(string password)
43+
{
44+
ArgumentException.ThrowIfNullOrWhiteSpace(password);
45+
this.Password = password;
46+
return this;
47+
}
48+
49+
/// <inheritdoc/>
50+
public override DigestAuthenticationSchemeDefinition Build()
51+
{
52+
if (string.IsNullOrWhiteSpace(this.Username)) throw new NullReferenceException("The username must be set");
53+
if (string.IsNullOrWhiteSpace(this.Password)) throw new NullReferenceException("The password must be set");
54+
return new()
55+
{
56+
Use = this.Secret,
57+
Username = this.Username,
58+
Password = this.Password
59+
};
60+
}
61+
62+
AuthenticationSchemeDefinition IAuthenticationSchemeDefinitionBuilder.Build() => this.Build();
63+
64+
}

src/ServerlessWorkflow.Sdk.Builders/Interfaces/IAuthenticationPolicyDefinitionBuilder.cs

+18
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,30 @@ public interface IAuthenticationPolicyDefinitionBuilder
3737
/// <returns>A new <see cref="IBasicAuthenticationSchemeDefinitionBuilder"/></returns>
3838
IBearerAuthenticationSchemeDefinitionBuilder Bearer();
3939

40+
/// <summary>
41+
/// Configures the policy to use 'Certificate' authentication
42+
/// </summary>
43+
/// <returns>A new <see cref="ICertificateAuthenticationSchemeDefinitionBuilder"/></returns>
44+
ICertificateAuthenticationSchemeDefinitionBuilder Certificate();
45+
46+
/// <summary>
47+
/// Configures the policy to use 'Digest' authentication
48+
/// </summary>
49+
/// <returns>A new <see cref="IDigestAuthenticationSchemeDefinitionBuilder"/></returns>
50+
IDigestAuthenticationSchemeDefinitionBuilder Digest();
51+
4052
/// <summary>
4153
/// Configures the policy to use 'OAuth2' authentication
4254
/// </summary>
4355
/// <returns>A new <see cref="IBasicAuthenticationSchemeDefinitionBuilder"/></returns>
4456
IOAuth2AuthenticationSchemeDefinitionBuilder OAuth2();
4557

58+
/// <summary>
59+
/// Configures the policy to use 'OpenIDConnect' authentication
60+
/// </summary>
61+
/// <returns>A new <see cref="IOpenIDConnectAuthenticationSchemeDefinitionBuilder"/></returns>
62+
IOpenIDConnectAuthenticationSchemeDefinitionBuilder OpenIDConnect();
63+
4664
/// <summary>
4765
/// Builds the configured <see cref="AuthenticationPolicyDefinition"/>
4866
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Defines the fundamentals of a service used to build <see cref="CertificateAuthenticationSchemeDefinition"/>s
18+
/// </summary>
19+
public interface ICertificateAuthenticationSchemeDefinitionBuilder
20+
: IAuthenticationSchemeDefinitionBuilder<CertificateAuthenticationSchemeDefinition>
21+
{
22+
23+
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Defines the fundamentals of a service used to build <see cref="DigestAuthenticationSchemeDefinition"/>s
18+
/// </summary>
19+
public interface IDigestAuthenticationSchemeDefinitionBuilder
20+
: IAuthenticationSchemeDefinitionBuilder<DigestAuthenticationSchemeDefinition>
21+
{
22+
23+
/// <summary>
24+
/// Sets the username to use
25+
/// </summary>
26+
/// <param name="username">The username to use</param>
27+
/// <returns>The configured <see cref="IDigestAuthenticationSchemeDefinitionBuilder"/></returns>
28+
IDigestAuthenticationSchemeDefinitionBuilder WithUsername(string username);
29+
30+
/// <summary>
31+
/// Sets the password to use
32+
/// </summary>
33+
/// <param name="password">The password to use</param>
34+
/// <returns>The configured <see cref="IDigestAuthenticationSchemeDefinitionBuilder"/></returns>
35+
IDigestAuthenticationSchemeDefinitionBuilder WithPassword(string password);
36+
37+
}

src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOAuth2AuthenticationClientDefinitionBuilder.cs

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ public interface IOAuth2AuthenticationClientDefinitionBuilder
3333
/// <returns>The configured <see cref="IOAuth2AuthenticationClientDefinitionBuilder"/></returns>
3434
IOAuth2AuthenticationClientDefinitionBuilder WithSecret(string secret);
3535

36+
/// <summary>
37+
/// Sets the OAUTH2 client's assertion
38+
/// </summary>
39+
/// <param name="assertion">A JWT containing a signed assertion with the application credentials</param>
40+
/// <returns>The configured <see cref="IOAuth2AuthenticationClientDefinitionBuilder"/></returns>
41+
IOAuth2AuthenticationClientDefinitionBuilder WithAssertion(string assertion);
42+
43+
/// <summary>
44+
/// Sets the OAUTH2 client's authentication method
45+
/// </summary>
46+
/// <param name="method">The authentication method to use to authenticate the client</param>
47+
/// <returns>The configured <see cref="IOAuth2AuthenticationClientDefinitionBuilder"/></returns>
48+
IOAuth2AuthenticationClientDefinitionBuilder WithAuthenticationMethod(string method);
49+
3650
/// <summary>
3751
/// Builds the configured <see cref="OAuth2AuthenticationClientDefinition"/>
3852
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Defines the fundamentals of a service used to build <see cref="OAuth2AuthenticationEndpointsDefinition"/>s
18+
/// </summary>
19+
public interface IOAuth2AuthenticationEndpointsDefinitionBuilder
20+
{
21+
22+
/// <summary>
23+
/// Configures the <see cref="OAuth2AuthenticationEndpointsDefinition"/> to build to use the specified token endpoint relative uri
24+
/// </summary>
25+
/// <param name="uri">The relative uri of the token endpoint to use</param>
26+
/// <returns>The configured <see cref="IOAuth2AuthenticationEndpointsDefinitionBuilder"/></returns>
27+
IOAuth2AuthenticationEndpointsDefinitionBuilder WithTokenEndpoint(Uri uri);
28+
29+
/// <summary>
30+
/// Configures the <see cref="OAuth2AuthenticationEndpointsDefinition"/> to build to use the specified revocation endpoint relative uri
31+
/// </summary>
32+
/// <param name="uri">The relative uri of the revocation endpoint to use</param>
33+
/// <returns>The configured <see cref="IOAuth2AuthenticationEndpointsDefinitionBuilder"/></returns>
34+
IOAuth2AuthenticationEndpointsDefinitionBuilder WithRevocationEndpoint(Uri uri);
35+
36+
/// <summary>
37+
/// Configures the <see cref="OAuth2AuthenticationEndpointsDefinition"/> to build to use the specified introspection endpoint relative uri
38+
/// </summary>
39+
/// <param name="uri">The relative uri of the introspection endpoint to use</param>
40+
/// <returns>The configured <see cref="IOAuth2AuthenticationEndpointsDefinitionBuilder"/></returns>
41+
IOAuth2AuthenticationEndpointsDefinitionBuilder WithIntrospectionEndpoint(Uri uri);
42+
43+
/// <summary>
44+
/// Builds the configured <see cref="OAuth2AuthenticationEndpointsDefinition"/>
45+
/// </summary>
46+
/// <returns>The configured <see cref="OAuth2AuthenticationEndpointsDefinition"/></returns>
47+
OAuth2AuthenticationEndpointsDefinition Build();
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Defines the fundamentals of a service used to build <see cref="OAuth2AuthenticationRequestDefinition"/>s
18+
/// </summary>
19+
public interface IOAuth2AuthenticationRequestDefinitionBuilder
20+
{
21+
22+
/// <summary>
23+
/// Configures the <see cref="OAuth2AuthenticationRequestDefinition"/> to build to use the specified encoding
24+
/// </summary>
25+
/// <param name="encoding">The encoding to use</param>
26+
/// <returns>The configured <see cref="IOAuth2AuthenticationRequestDefinitionBuilder"/></returns>
27+
IOAuth2AuthenticationRequestDefinitionBuilder WithEncoding(string encoding);
28+
29+
/// <summary>
30+
/// Builds the configured <see cref="OAuth2AuthenticationRequestDefinition"/>
31+
/// </summary>
32+
/// <returns>A new <see cref="OAuth2AuthenticationRequestDefinition"/></returns>
33+
OAuth2AuthenticationRequestDefinition Build();
34+
35+
}

0 commit comments

Comments
 (0)