/// <summary>
 /// Enforces invariants on a <see cref="BearerAccessToken"/>.
 /// </summary>
 /// <param name="token">An instance of <see cref="BearerAccessToken"/></param>
 public static void EnforceInvariants(this BearerAccessToken token)
 {
     if (token.Expires == null)
     {
         throw new InvalidOperationException("Expires must not be null. Call SetExpires() to set");
     }
 }
Exemple #2
0
        public Task <BearerAccessToken> Get(string key)
        {
            BearerAccessToken value = null;

            _store.TryGetValue(key, out value);
            return(Task.FromResult(value));
        }
Exemple #3
0
 public Task Update(string key, BearerAccessToken token)
 {
     if (!_store.ContainsKey(key))
     {
         throw new InvalidOperationException($"No token \"{key}\" found to update");
     }
     _store[key] = token;
     return(Task.CompletedTask);
 }
 /// <summary>
 /// Inserts or replaces a <see cref="BearerAccessToken"/>.
 /// </summary>
 /// <param name="key">The identifier key for the token.</param>
 /// <param name="token">The token as <see cref="BearerAccessToken"/>.</param>
 public Task InsertOrReplace(string key, BearerAccessToken token)
 {
     _store[key] = token;
     return(Task.CompletedTask);
 }
 /// <summary>
 /// Derive and set the Expires property on a <see cref="BearerAccessToken"/>.
 /// </summary>
 /// <param name="token">A instance of <see cref="BearerAccessToken"/>.</param>
 /// <param name="issuedDateTime">Approximate date and time that the token was issued.</param>
 /// <returns>The derived Expires value.</returns>
 public static DateTime SetExpires(this BearerAccessToken token, DateTime issuedDateTime)
 {
     token.Expires = issuedDateTime.ToUniversalTime().AddSeconds(token.ExpiresIn);
     return(token.Expires.Value);
 }