コード例 #1
0
        public PushNotificationsClient(Options options, Authenticator authenticator = null)
        {
            if (ReferenceEquals(null, options)) throw new ArgumentNullException(nameof(options));
            this.options = options;

            this.authenticator = authenticator;
        }
コード例 #2
0
 Authenticator(Authenticator authenticator, TokenResponse tokenResponse)
 {
     this.authorizationEndpoint = new Uri(authenticator.options.Authority, "connect/token");
     this.options = authenticator.options;
     current = tokenResponse;
     InitializedAt = DateTime.UtcNow;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
ファイル: Send.cs プロジェクト: Elders/Pushnotifications
        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);
        }
コード例 #5
0
        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;
        }