35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Text.RegularExpressions;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace BS.Shared.Core
|
|||
|
|
{
|
|||
|
|
public static class TokenUtils
|
|||
|
|
{
|
|||
|
|
public static string CreateTemporaryUrlByToken(string link, string token)
|
|||
|
|
{
|
|||
|
|
if (link.Contains("tenant"))
|
|||
|
|
link = RemoveAuthenticationInfoFromUri(link);
|
|||
|
|
|
|||
|
|
var addChar = link.Contains("?") ? "&" : "?";
|
|||
|
|
|
|||
|
|
var finalUri = string.Format("{0}{1}token={2}", link, addChar, token);
|
|||
|
|
|
|||
|
|
return finalUri;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static string RemoveAuthenticationInfoFromUri(string navigateUri)
|
|||
|
|
{
|
|||
|
|
var regex = new Regex(@"[\&|\?]?token\=[A-Za-z0-9]+|[\&|\?]?tenant\=[A-Za-z0-9]+|[\&|\?]?username\=[A-Za-z0-9.]+");
|
|||
|
|
var splittedUri = regex.Split(navigateUri.Split('?')[1]);
|
|||
|
|
var cleanedSplittedUri = splittedUri.Where(t => !string.IsNullOrWhiteSpace(t)).ToArray();
|
|||
|
|
var uriValues = cleanedSplittedUri.Aggregate(string.Empty, (current, item) => current + item);
|
|||
|
|
|
|||
|
|
return navigateUri.Split('?')[0] + "?" + uriValues;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|