Skip to content

Commit

Permalink
Sr at21 integration test cofig3 (#233)
Browse files Browse the repository at this point in the history
* unauth systemregister

* reauth systemregister

* add profileclient and it's dependencies

* access token etc towards profile api

* fix comment
  • Loading branch information
simen-rekkedal authored Apr 24, 2024
1 parent ae6ac9f commit 8501d92
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 230 deletions.

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>
///
/// </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

0 comments on commit 8501d92

Please sign in to comment.