forked from projectkudu/ARMClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update to ADAL 2.14.201151115 version
- Loading branch information
Showing
20 changed files
with
550 additions
and
285 deletions.
There are no files selected for viewing
388 changes: 218 additions & 170 deletions
388
ARMClient.Authentication/AADAuthentication/BaseAuthHelper.cs
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.IdentityModel.Clients.ActiveDirectory; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace ARMClient.Authentication.Contracts | ||
{ | ||
public class CustomTokenCache : TokenCache | ||
{ | ||
private Dictionary<string, TokenCacheInfo> _caches; | ||
|
||
public CustomTokenCache(string state = null) | ||
{ | ||
if (state == null) | ||
{ | ||
_caches = new Dictionary<string, TokenCacheInfo>(); | ||
} | ||
else | ||
{ | ||
_caches = JsonConvert.DeserializeObject<Dictionary<string, TokenCacheInfo>>(state); | ||
} | ||
} | ||
|
||
public IEnumerable<TokenCacheInfo> GetValues(string resource) | ||
{ | ||
return _caches.Values.Where(c => c.Resource == resource); | ||
} | ||
|
||
public string GetState() | ||
{ | ||
return JObject.FromObject(_caches).ToString(); | ||
} | ||
|
||
public bool TryGetValue(string tenantId, string resource, out TokenCacheInfo cacheInfo) | ||
{ | ||
return _caches.TryGetValue(GetKey(tenantId, resource), out cacheInfo); | ||
} | ||
|
||
public TokenCacheInfo Get(string tenantId, string resource) | ||
{ | ||
return _caches[GetKey(tenantId, resource)]; | ||
} | ||
|
||
public void Add(TokenCacheInfo cacheInfo) | ||
{ | ||
_caches[GetKey(cacheInfo.TenantId, cacheInfo.Resource)] = cacheInfo; | ||
} | ||
|
||
private string GetKey(string tenantId, string resource) | ||
{ | ||
return String.Format("{0}::{1}", tenantId, resource); | ||
} | ||
} | ||
} |
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,44 @@ | ||
using System; | ||
using Microsoft.IdentityModel.Clients.ActiveDirectory; | ||
|
||
namespace ARMClient.Authentication.Contracts | ||
{ | ||
public class TokenCacheInfo | ||
{ | ||
public TokenCacheInfo() | ||
{ | ||
} | ||
|
||
public TokenCacheInfo(string tenantId, string appId, string appKey, string resource, AuthenticationResult result) | ||
: this(resource, result) | ||
{ | ||
AppId = appId; | ||
AppKey = appKey; | ||
TenantId = tenantId; | ||
} | ||
|
||
public TokenCacheInfo(string resource, AuthenticationResult result) | ||
{ | ||
AccessToken = result.AccessToken; | ||
DisplayableId = result.UserInfo == null ? null : result.UserInfo.DisplayableId; | ||
ExpiresOn = result.ExpiresOn; | ||
RefreshToken = result.RefreshToken; | ||
Resource = resource; | ||
TenantId = result.TenantId; | ||
} | ||
|
||
public string AppId { get; set; } | ||
public string AppKey { get; set; } | ||
public string AccessToken { get; set; } | ||
public string DisplayableId { get; set; } | ||
public DateTimeOffset ExpiresOn { get; set; } | ||
public string RefreshToken { get; set; } | ||
public string Resource { get; set; } | ||
public string TenantId { get; set; } | ||
|
||
public string CreateAuthorizationHeader() | ||
{ | ||
return String.Format("Bearer {0}", AccessToken); | ||
} | ||
} | ||
} |
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
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
17 changes: 9 additions & 8 deletions
17
ARMClient.Authentication/TokenStorage/MemoryTokenStorage.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace ARMClient.Authentication.Utilities | ||
{ | ||
public static class Utils | ||
{ | ||
static TraceListener _traceListener; | ||
|
||
public static TraceListener Trace | ||
{ | ||
get { return _traceListener ?? DefaultTraceListener.Default; } | ||
} | ||
|
||
public static void SetTraceListener(TraceListener listener) | ||
{ | ||
_traceListener = listener; | ||
} | ||
|
||
class DefaultTraceListener : TraceListener | ||
{ | ||
public readonly static TraceListener Default = new DefaultTraceListener(); | ||
|
||
public override void Write(string message) | ||
{ | ||
System.Diagnostics.Trace.Write(message); | ||
} | ||
|
||
public override void WriteLine(string message) | ||
{ | ||
System.Diagnostics.Trace.WriteLine(message); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net451" /> | ||
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="1.0.5" targetFramework="net451" /> | ||
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.14.201151115" targetFramework="net45" /> | ||
<package id="Newtonsoft.Json" version="6.0.6" targetFramework="net451" /> | ||
</packages> |
Oops, something went wrong.