Skip to content
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

Sr at21 integration test cofig3 #233

Merged
merged 6 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,109 +1,91 @@
namespace Altinn.Authentication.UI.Core.Common;
namespace Altinn.Authentication.UI.Core.Extensions;

public static class HttpClientExtensions
/// <summary>
/// This extension is created to make it easy to add a bearer token to a HttpRequests.
/// </summary>
public static class HttpClientExtension
{

/// <summary>
/// Extensionmethod to add Authorization token and access token to the header
/// </summary>
/// <param name="httpClient"></param>
/// <param name="authorizationToken"></param>
/// <param name="requestURI"></param>
/// <param name="content"></param>
/// <param name="platformAccessToken"></param>
/// <returns></returns>
public static Task<HttpResponseMessage> PostAsync(
this HttpClient httpClient,
string authorizationToken, string requestURI,
HttpContent content, string? platformAccessToken = null)
/// <summary>
/// Extension that add authorization header to request.
/// </summary>
/// <param name="httpClient">The HttpClient.</param>
/// <param name="authorizationToken">the authorization token (jwt).</param>
/// <param name="requestUri">The request Uri.</param>
/// <param name="content">The http content.</param>
/// <param name="platformAccessToken">The platformAccess tokens.</param>
/// <returns>A HttpResponseMessage.</returns>
public static Task<HttpResponseMessage> PostAsync(this HttpClient httpClient, string authorizationToken, string requestUri, HttpContent content, string platformAccessToken = null)
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUri);
request.Headers.Add("Authorization", "Bearer " + authorizationToken);
request.Content = content;
if (!string.IsNullOrEmpty(platformAccessToken))
{
HttpRequestMessage request = new(HttpMethod.Post, requestURI);
request.Headers.Add("Authorization", "Bearer " + authorizationToken);
request.Content = content;
if(platformAccessToken is not null && platformAccessToken.Length > 0)
{
request.Headers.Add("PlatformAccessToken", platformAccessToken);
}

return httpClient.SendAsync(request, CancellationToken.None);
request.Headers.Add("PlatformAccessToken", platformAccessToken);
}

/// <summary>
/// Extensionmethod to add Authorization token and access token to the header
/// </summary>
/// <param name="httpClient"></param>
/// <param name="authorizationToken"></param>
/// <param name="requestURI"></param>
/// <param name="content"></param>
/// <param name="platformAccessToken"></param>
/// <returns></returns>
public static Task<HttpResponseMessage> PutAsync(
this HttpClient httpClient,
string authorizationToken, string requestURI,
HttpContent content, string? platformAccessToken = null)
{
HttpRequestMessage request = new(HttpMethod.Put, requestURI);
request.Headers.Add("Authorization", "Bearer " + authorizationToken);
request.Content = content;

if(platformAccessToken is not null && platformAccessToken.Length > 0)
{
request.Headers.Add("PlatformAccessToken", platformAccessToken);
}
return httpClient.SendAsync(request, CancellationToken.None);
}

return httpClient.SendAsync(request, CancellationToken.None);
/// <summary>
/// Extension that add authorization header to request.
/// </summary>
/// <param name="httpClient">The HttpClient.</param>
/// <param name="authorizationToken">the authorization token (jwt).</param>
/// <param name="requestUri">The request Uri.</param>
/// <param name="content">The http content.</param>
/// <param name="platformAccessToken">The platformAccess tokens.</param>
/// <returns>A HttpResponseMessage.</returns>
public static Task<HttpResponseMessage> PutAsync(this HttpClient httpClient, string authorizationToken, string requestUri, HttpContent content, string platformAccessToken = null)
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, requestUri);
request.Headers.Add("Authorization", "Bearer " + authorizationToken);
request.Content = content;
if (!string.IsNullOrEmpty(platformAccessToken))
{
request.Headers.Add("PlatformAccessToken", platformAccessToken);
}

return httpClient.SendAsync(request, CancellationToken.None);
}

/// <summary>
/// Extensionmethod to add Authorization token and access token to the header
/// </summary>
/// <param name="httpClient"></param>
/// <param name="authorizationToken"></param>
/// <param name="requestURI"></param>
/// <param name="content"></param>
/// <param name="platformAccessToken"></param>
/// <returns></returns>
public static Task<HttpResponseMessage> GetAsync(
this HttpClient httpClient,
string authorizationToken, string requestURI,
HttpContent content, string? platformAccessToken = null)
/// <summary>
/// Extension that add authorization header to request.
/// </summary>
/// <param name="httpClient">The HttpClient.</param>
/// <param name="authorizationToken">the authorization token (jwt).</param>
/// <param name="requestUri">The request Uri.</param>
/// <param name="platformAccessToken">The platformAccess tokens.</param>
/// <returns>A HttpResponseMessage.</returns>
public static Task<HttpResponseMessage> GetAsync(this HttpClient httpClient, string authorizationToken, string requestUri, string platformAccessToken = null)
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Add("Authorization", "Bearer " + authorizationToken);
if (!string.IsNullOrEmpty(platformAccessToken))
{
HttpRequestMessage request = new(HttpMethod.Get, requestURI);
request.Headers.Add("Authorization", "Bearer " + authorizationToken);
request.Content = content;

if(platformAccessToken is not null && platformAccessToken.Length > 0)
{
request.Headers.Add("PlatformAccessToken", platformAccessToken);
}

return httpClient.SendAsync(request, CancellationToken.None);
request.Headers.Add("PlatformAccessToken", platformAccessToken);
}

/// <summary>
/// Extensionmethod to add Authorization token and access token to the header
/// </summary>
/// <param name="httpClient"></param>
/// <param name="authorizationToken"></param>
/// <param name="requestURI"></param>
/// <param name="content"></param>
/// <param name="platformAccessToken"></param>
/// <returns></returns>
public static Task<HttpResponseMessage> DeleteAsync(
this HttpClient httpClient,
string authorizationToken, string requestURI,
HttpContent content, string? platformAccessToken = null)
{
HttpRequestMessage request = new(HttpMethod.Delete, requestURI);
request.Headers.Add("Authorization", "Bearer " + authorizationToken);
request.Content = content;

if(platformAccessToken is not null && platformAccessToken.Length > 0)
{
request.Headers.Add("PlatformAccessToken", platformAccessToken);
}
return httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead, CancellationToken.None);
}

return httpClient.SendAsync(request, CancellationToken.None);
/// <summary>
/// Extension that add authorization header to request.
/// </summary>
/// <param name="httpClient">The HttpClient.</param>
/// <param name="authorizationToken">the authorization token (jwt).</param>
/// <param name="requestUri">The request Uri.</param>
/// <param name="platformAccessToken">The platformAccess tokens.</param>
/// <returns>A HttpResponseMessage.</returns>
public static Task<HttpResponseMessage> DeleteAsync(this HttpClient httpClient, string authorizationToken, string requestUri, string platformAccessToken = null)
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, requestUri);
request.Headers.Add("Authorization", "Bearer " + authorizationToken);
if (!string.IsNullOrEmpty(platformAccessToken))
{
request.Headers.Add("PlatformAccessToken", platformAccessToken);
}

return httpClient.SendAsync(request, CancellationToken.None);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@

namespace Altinn.Authentication.UI.Core.UserProfiles;

/// <summary>
///
simen-rekkedal marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public interface IUserProfileClient
{
/// <summary>
/// Retrieves the userprofile by id from the Platforms Profile API
/// </summary>
/// <param name="userid"></param>
/// <returns></returns>
public Task<UserProfile> GetUserProfile(int userid);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ namespace Altinn.Authentication.UI.Core.UserProfiles;

public interface IUserProfileService
{
/// <summary>
/// Get the userprofile from the Platform Profile API
/// </summary>
/// <param name="userid"></param>
/// <returns></returns>
Task<UserProfile> GetUserProfile(int userid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public UserProfileService(
_profileClient = profileClient;
}

/// <inheritdoc/>
public async Task<UserProfile> GetUserProfile(int userid)
{
UserProfile userProfile = await _profileClient.GetUserProfile(userid);
Expand Down
Loading
Loading