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);
      }
    }
Exemple #2
0
        public String GenerateWsJwt(JsonWebToken.Payload.WebserviceResponse response)
        {
            String header    = UrlSafeBase64Encode(CreateSerializedHeader());
            String body      = UrlSafeBase64Encode(CreateWSPayload(response));
            String content   = header + "." + body;
            String signature = CreateSignature(content);

            return(content + "." + signature);
        }
Exemple #3
0
        private string CreateWSPayload(JsonWebToken.Payload.WebserviceResponse response)
        {
            var iat          = (int)(System.DateTime.UtcNow - new System.DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
            var jwtContainer = new JsonWebToken.Payload()
            {
                Issuer              = issuer,
                Audience            = "google",
                Type                = "loyaltywebservice",
                IssuedAtTimeSeconds = iat,
                Objects             = new JsonWebToken.Payload.Content()
                {
                    loyaltyObjects     = loyaltyObjects,
                    offerObjects       = offerObjects,
                    webserviceResponse = response
                },
            };

            return(NewtonsoftJsonSerializer.Instance.Serialize(jwtContainer));
        }