public PushNotificationsClient(Options options, Authenticator authenticator = null) { if (ReferenceEquals(null, options)) throw new ArgumentNullException(nameof(options)); this.options = options; this.authenticator = authenticator; }
Authenticator(Authenticator authenticator, TokenResponse tokenResponse) { this.authorizationEndpoint = new Uri(authenticator.options.Authority, "connect/token"); this.options = authenticator.options; current = tokenResponse; InitializedAt = DateTime.UtcNow; }
IRestRequest CreateRestRequest(string resource, Method method, Authenticator inlineAuthenticator = null) { var request = new RestRequest(resource, method); request.RequestFormat = DataFormat.Json; request.JsonSerializer = options.JsonSerializer; request.AddAuthorizationBearerHeader(Eval(inlineAuthenticator)); return request; }
public async Task<IRestResponse> Send(PushNotificationModel model, Authenticator authenticator = null) { const string Resource = "PushNotifications/Send"; if (ReferenceEquals(null, model)) throw new ArgumentNullException(nameof(model)); var request = CreateRestRequest(Resource, Method.POST, authenticator) .AddJsonBody(model); return await CreateRestClient().ExecuteAsync(request); }
Authenticator Eval(Authenticator local) { if (ReferenceEquals(null, authenticator) && ReferenceEquals(null, local)) throw new ArgumentNullException(nameof(authenticator), "Not a valid authenticator is specified. You can initialize a default Authenticator on Client.ctor(...) or specify explicitly the Authenticator with each call. One of the two is mandatory."); if (ReferenceEquals(null, local) == false) return local; if (authenticator.ExpiresIn < 120) authenticator = authenticator.GetClientCredentialsAuthenticatorAsync().Result; return authenticator; }