// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var hubConnection   = "Endpoint=sb://thnotify1.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=Z2Xpa9dMYJLipI26LS1hltCZw8U4KI41NfnPucWkWqw=";
            var hubName         = "not1";
            var hubClient       = NotificationHubClient.CreateClientFromConnectionString(hubConnection, hubName);
            var registrationSvc = new AzureRegistrationService(hubClient);

            services.AddSingleton <IRegistrationService>(registrationSvc);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = "yourdomain.com",
                    ValidAudience    = "yourdomain.com",
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["SecurityKey"]))
                };
            });

            services.AddMvc();
        }
Example #2
0
        static async Task DoIt()
        {
            var hubConnection = "Endpoint=sb://thnotify1.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=Z2Xpa9dMYJLipI26LS1hltCZw8U4KI41NfnPucWkWqw=";
            var hubName       = "not1";
            var hubClient     = NotificationHubClient.CreateClientFromConnectionString(hubConnection, hubName);

            string chromePnsHandle  = "APA91bEGv8n_2g_5wv1Cxj6Q9KumQZdLp8uoSzAtdhIJW27cGglow33CDHqpDFEXhae5dwRVN-m99W_tiHBriMmC5DDRxd_vR-uQPNiOdPDt2XK4qLtMMO2aJQlGq1wMihx-b7IcDZl528Ocx6I_x5ug4e6UVkPYbQ";
            var    deviceIdentifier = "device4567";
            var    userIdentifier   = "user1234";

            // Register a device and tag it with who it belongs to
            var regSvc = new AzureRegistrationService(hubClient);

            var registration = new Registration
            {
                DeviceIdentifier = deviceIdentifier,
                PnsHandle        = chromePnsHandle,
                Platform         = Platform.Google
            };

            regSvc.CreateRegistration(registration, new string[] { userIdentifier, deviceIdentifier });

            // Send a notification to a user (will go to all the devices they have registered on)
            var notifySvc = new AzureNotificationService(hubClient);
            await notifySvc.SendTextNotification("Hello, Gearstone!", userIdentifier);
        }