-
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
Feature/488068 auth common backend and accounts apis #37
Merged
Ravi-SharmaGautam
merged 12 commits into
main
from
feature/488068-auth-common-backend-and-accounts-apis
Jan 14, 2025
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
64e675f
488068: Defra APis - common backend and accounts auth handler
hyadaveviden 7ae584c
488068: Prn HttpClient for calling common backend and accounts APIs
hyadaveviden 4f27ecb
488068: added support for both accounts and prn Client Id in Bearer t…
hyadaveviden a77bbee
488068: merged main
hyadaveviden 6fb5c64
488068: bug fix - added named Http clients
hyadaveviden df9d5ea
488068: removed redundant file
hyadaveviden 199b68e
4880687: handled default http client name if a named client is not se…
hyadaveviden 583e1f8
488068: code review fixes
hyadaveviden 725b7eb
refactored the code
a5a259f
merged remote
9d192a2
Merge branch 'main' into feature/488068-auth-common-backend-and-accou…
hyadaveviden a21ff28
corrected settings.json file
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
38 changes: 38 additions & 0 deletions
38
src/EprPrnIntegration.Common/Middleware/PrnServiceAuthorisationHandler.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,38 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Net.Http.Headers; | ||
using Azure.Core; | ||
using Azure.Identity; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace EprPrnIntegration.Common.Middleware; | ||
|
||
[ExcludeFromCodeCoverage] | ||
public class PrnServiceAuthorisationHandler : DelegatingHandler | ||
{ | ||
private readonly TokenRequestContext _tokenRequestContext; | ||
private readonly DefaultAzureCredential? _credentials; | ||
Ehsan-Hatami marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public PrnServiceAuthorisationHandler(IOptions<Configuration.Service> config) | ||
{ | ||
if (!string.IsNullOrEmpty(config.Value.ClientId)) | ||
{ | ||
_tokenRequestContext = new TokenRequestContext([config.Value.ClientId]); | ||
hyadaveviden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_credentials = new DefaultAzureCredential(); | ||
} | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
await AddDefaultToken(request, cancellationToken); | ||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
|
||
private async Task AddDefaultToken(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
if (_credentials != null) | ||
{ | ||
var tokenResult = await _credentials.GetTokenAsync(_tokenRequestContext, cancellationToken); | ||
request.Headers.Authorization = new AuthenticationHeaderValue(Constants.HttpHeaderNames.Bearer, tokenResult.Token); | ||
} | ||
} | ||
} |
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.
You have named this client but where this has been used?
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.
changed to default