public virtual void ProcessRequest(HttpContext context)
        {
            try {
                HttpRequest request = context.Request;

                // get credentials and settings
                WobCredentials credentials = new WobCredentials(
                    WebConfigurationManager.AppSettings["ServiceAccountId"],
                    WebConfigurationManager.AppSettings["ServiceAccountPrivateKey"],
                    WebConfigurationManager.AppSettings["ApplicationName"],
                    WebConfigurationManager.AppSettings["IssuerId"]);

                string loyaltyClassId   = WebConfigurationManager.AppSettings["LoyaltyClassId"];
                string loyaltyObjectId  = WebConfigurationManager.AppSettings["LoyaltyObjectId"];
                string offerClassId     = WebConfigurationManager.AppSettings["OfferClassId"];
                string offerObjectId    = WebConfigurationManager.AppSettings["OfferObjectId"];
                string giftCardClassId  = WebConfigurationManager.AppSettings["GiftCardClassId"];
                string giftCardObjectId = WebConfigurationManager.AppSettings["GiftCardObjectId"];

                // OAuth - setup certificate based on private key file
                X509Certificate2 certificate = new X509Certificate2(
                    AppDomain.CurrentDomain.BaseDirectory + credentials.serviceAccountPrivateKey,
                    "notasecret",
                    X509KeyStorageFlags.Exportable);

                WobUtils utils = new WobUtils(credentials.serviceAccountId, certificate);

                // get the object type
                string type = request.Params["type"];

                if (type.Equals("loyalty"))
                {
                    LoyaltyObject loyaltyObject = Loyalty.generateLoyaltyObject(credentials.IssuerId, loyaltyClassId, loyaltyObjectId);
                    utils.addObject(loyaltyObject);
                }
                else if (type.Equals("offer"))
                {
                    OfferObject offerObject = Offer.generateOfferObject(credentials.IssuerId, offerClassId, offerObjectId);
                    utils.addObject(offerObject);
                }
                else if (type.Equals("giftcard"))
                {
                    GiftCardObject giftCardObject = GiftCard.generateGiftCardObject(credentials.IssuerId, giftCardClassId, giftCardObjectId);
                    utils.addObject(giftCardObject);
                }

                // generate the JWT
                string jwt = utils.GenerateJwt();

                HttpResponse response = context.Response;
                response.Write(jwt);
                //response.ContentType = "text/xml";
            }
            catch (Exception e) {
                Console.Write(e.StackTrace);
            }
        }
Ejemplo n.º 2
0
        public virtual void ProcessRequest(HttpContext context)
        {
            try {
                HttpRequest request = context.Request;

                WobCredentials credentials = new WobCredentials(
                    WebConfigurationManager.AppSettings["ServiceAccountId"],
                    WebConfigurationManager.AppSettings["ServiceAccountPrivateKey"],
                    WebConfigurationManager.AppSettings["ApplicationName"],
                    WebConfigurationManager.AppSettings["IssuerId"]);

                // OAuth - setup certificate based on private key file
                X509Certificate2 certificate = new X509Certificate2(
                    AppDomain.CurrentDomain.BaseDirectory + credentials.serviceAccountPrivateKey,
                    "notasecret",
                    X509KeyStorageFlags.Exportable);

                WobUtils          utils      = null;
                WebserviceRequest webRequest = null;
                JsonWebToken.Payload.WebserviceResponse webResponse = null;
                string jwt = null;

                ReadEntityBodyMode read        = request.ReadEntityBodyMode;
                Stream             inputStream = null;

                if (read == ReadEntityBodyMode.None)
                {
                    inputStream = request.GetBufferedInputStream();
                }
                else
                {
                    inputStream = request.InputStream;
                }

                webRequest = NewtonsoftJsonSerializer.Instance.Deserialize <WebserviceRequest>(inputStream);

                if (webRequest.Method.Equals("signup"))
                {
                    webResponse = new JsonWebToken.Payload.WebserviceResponse()
                    {
                        Message = "Welcome to baconrista",
                        Result  = "approved"
                    };
                }
                else
                {
                    webResponse = new JsonWebToken.Payload.WebserviceResponse()
                    {
                        Message = "Thanks for linking to baconrista",
                        Result  = "approved"
                    };
                }

                utils = new WobUtils(credentials.IssuerId, certificate);

                string        linkId        = webRequest.Params.LinkingId;
                LoyaltyObject loyaltyObject = Loyalty.generateLoyaltyObject(credentials.IssuerId, "LoyaltyClass", (linkId != null) ? linkId : "LoyaltyObject");
                utils.addObject(loyaltyObject);

                jwt = utils.GenerateWsJwt(webResponse);

                HttpResponse response = context.Response;
                response.Write(jwt);
            }
            catch (Exception e) {
                Console.Write(e.StackTrace);
            }
        }