-
Notifications
You must be signed in to change notification settings - Fork 0
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
Authentication provider #40
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a5104e6
+ IClientAuthenticationProvider
JindrichSusen 21090e4
~ version to 2.2.0
JindrichSusen 9b1819a
+ Configuration extensions method
JindrichSusen 481b0eb
~ version to 2.2.1
JindrichSusen c2c12da
Comments added
JindrichSusen 9904cd2
~ version to 2.2.2
JindrichSusen c3d6d4a
+ License
JindrichSusen File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
Origam.Service.Core/Extensions/IConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#region license | ||
/* | ||
Copyright 2005 - 2024 Advantage Solutions, s. r. o. | ||
|
||
This file is part of ORIGAM (http://www.origam.org). | ||
|
||
ORIGAM is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
ORIGAM is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with ORIGAM. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#endregion | ||
|
||
using System; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Origam.Extensions | ||
{ | ||
public static class IConfigurationExtensions | ||
{ | ||
public static IConfigurationSection GetSectionOrThrow(this IConfiguration configuration, string key) | ||
{ | ||
var section = configuration.GetSection(key); | ||
if (!section.Exists()) | ||
{ | ||
throw new ArgumentException($"Section \"{key}\" was not found in configuration. Check your appsettings.json"); | ||
} | ||
return section; | ||
} | ||
|
||
public static string[] GetStringArrayOrThrow(this IConfiguration section) | ||
{ | ||
string[] stringArray = section.Get<string[]>(); | ||
if (stringArray == null || stringArray.Length == 0) | ||
{ | ||
throw new ArgumentException($"String array in section \"{section}\" was not found in configuration or was empty. Check your appsettings.json"); | ||
} | ||
return stringArray; | ||
} | ||
|
||
public static string[] GetStringArrayOrEmpty(this IConfiguration section) | ||
{ | ||
string[] stringArray = section.Get<string[]>(); | ||
if (stringArray == null || stringArray.Length == 0) | ||
{ | ||
return Array.Empty<string>(); | ||
} | ||
return stringArray; | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
Origam.Service.Core/Extensions/IConfigurationSectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#region license | ||
|
||
/* | ||
Copyright 2005 - 2024 Advantage Solutions, s. r. o. | ||
|
||
This file is part of ORIGAM (http://www.origam.org). | ||
|
||
ORIGAM is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
ORIGAM is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with ORIGAM. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#endregion | ||
|
||
using System; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Origam.Extensions | ||
{ | ||
public static class IConfigurationSectionExtensions | ||
{ | ||
public static string GetStringOrThrow(this IConfigurationSection section, string key) | ||
{ | ||
string stringValue = section[key]; | ||
if (stringValue == null) | ||
{ | ||
throw new ArgumentException($"Key \"{key}\" was not found in configuration in section \"{section.Path}\". Check your appsettings.json"); | ||
} | ||
return stringValue; | ||
} | ||
|
||
public static bool GetBoolOrThrow(this IConfigurationSection section, string key) | ||
{ | ||
string stringValue = section.GetStringOrThrow(key); | ||
bool success = Boolean.TryParse(stringValue, out bool boolValue); | ||
if (!success) | ||
{ | ||
throw new ArgumentException($"Cannot parse \"{key}\" to bool"); | ||
} | ||
return boolValue; | ||
} | ||
public static int GetIntOrThrow(this IConfigurationSection section, string key) | ||
{ | ||
string stringValue = section.GetStringOrThrow(key); | ||
bool success = int.TryParse(stringValue, out int intValue); | ||
if (!success) | ||
{ | ||
throw new ArgumentException($"Cannot parse \"{key}\" to int"); | ||
} | ||
return intValue; | ||
} | ||
|
||
public static IConfigurationSection GetSectionOrThrow(this IConfigurationSection section, string key) | ||
{ | ||
var subSection = section.GetSection(key); | ||
if (!subSection.Exists()) | ||
{ | ||
throw new ArgumentException($"Sub section \"{key}\" was not found in \"{section.Path}\" or it was empty. Check your appsettings.json"); | ||
} | ||
return subSection; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#region license | ||
/* | ||
Copyright 2005 - 2023 Advantage Solutions, s. r. o. | ||
|
||
This file is part of ORIGAM (http://www.origam.org). | ||
|
||
ORIGAM is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
ORIGAM is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with ORIGAM. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#endregion | ||
|
||
using System.Collections; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Origam.Service.Core; | ||
|
||
// Interface for authentication providers that can authenticate requests outgoing to external services. | ||
public interface IClientAuthenticationProvider | ||
{ | ||
// Implementations should return false if they cannot authenticate request to the url. | ||
// If the request can be authenticated the headers should be modified accordingly. | ||
bool TryAuthenticate(string url, Hashtable headers); | ||
|
||
// Receives IConfiguration parsed from the appsettings. There are no constraints on what should be read | ||
// from the configuration. Write what you need to the appsettings.json and read it here. | ||
// The configuration section for a class implementing this interface should have the same name as the class. | ||
void Configure(IConfiguration configuration); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's missing license info.