/// <summary> /// Adds a <see cref="LogonToken"/> instance to the collection. /// </summary> public int Add(LogonToken item) { return base.Add(item); }
/// <summary> /// Adds a range of <see cref="LogonToken"/> instances to the collection. /// </summary> public void AddRange(LogonToken[] items) { base.AddRange(items); }
/// <summary> /// Gets the API. /// </summary> /// <remarks>If we have a token of the form 'a-{username}', i.e. we're trying to log on the API, this returns the API /// with the given name. If we have a token of the form 't-{username}', we'll validate the logon token that was created /// in the database. In either case, we'll throw an exception if the account is inactive.</remarks> /// <returns></returns> public ApiKey GetApi(ref LogonToken token) { // reset... token = null; // do we have a full token? ApiKey api = null; string tokenString = this.ApiToken; if (!(string.IsNullOrEmpty(tokenString))) { token = LogonToken.GetByToken(tokenString); if (token == null) throw new InvalidOperationException(string.Format("The token '{0}' is invalid.", tokenString)); // update... token.UpdateExpiry(true); // set... api = token.ApiKey; if (api == null) throw new InvalidOperationException("'api' is null."); } else { string username = this.ApiUsername; if (!(string.IsNullOrEmpty(username))) { api = ApiKey.GetByUsername(username); if(api == null) throw new InvalidOperationException(string.Format("An API with username '{0}' was not found.", username)); } else throw new InvalidOperationException("Neither a logon token nor API key were provided in the request. Ensure a token was provided in the URL."); } // check... if(!(api.IsActive)) throw new InvalidOperationException(string.Format("The API account '{0}' is inactive.", api.Username)); // return... return api; }