Exemplo n.º 1
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestMessage req, TraceWriter log)
        {
            try
            {
                log.Info("C# HTTP trigger function processed a request.");

                var data = await RequestDecoder.Decode <SessionCreatePostModel>(req);

                try
                {
                    var jwt = Jwt.Decode(data.password);
                    if (jwt.subject != data.username)
                    {
                        throw new Exception("Username/JWT-subject mismatch");
                    }
                }
                catch
                {
                    throw new HttpResponseException(req.CreateErrorResponse(HttpStatusCode.Forbidden, "Forbidden"));
                }

                var response = new SessionResponseModel
                {
                    id       = Guid.NewGuid().ToString("N"),
                    username = data.username
                };
                return(req.CreateResponse(HttpStatusCode.OK, response));
            }
            catch (HttpResponseException error)
            {
                return(error.Response);
            }
        }
Exemplo n.º 2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestMessage req, TraceWriter log)
        {
            try
            {
                log.Info("C# HTTP trigger function processed a request.");

                var data = await RequestDecoder.Decode <TokenCreatePostModel>(req);

                var response = new TokenResponseModel
                {
                    id       = data.email,
                    name     = GetName(data.email),
                    iconURL  = Gravatar.GetImageUrl(data.email),
                    password = new Jwt(data.email).Encode()
                };
                return(req.CreateResponse(HttpStatusCode.OK, response));
            }
            catch (HttpResponseException error)
            {
                return(error.Response);
            }
        }