Esempio n. 1
0
        public async Task <IHttpActionResult> PostVerifyPerson(TokenForm token)
        {
            if (ModelState.IsValid)
            {
                if (token == null)
                {
                    Console.WriteLine("Token not received.");
                    return(BadRequest("Expected tokenid"));
                }
                else
                {
                    Console.WriteLine("Received verify-token with id " + token.tokenid);
                    var response = await scanningService.VerifyFingerprint(token.tokenid);

                    return(Ok(new MatchResponse()
                    {
                        match = response
                    }));
                }
            }
            else
            {
                return(BadRequest("Expected tokenid"));
            }
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> PostTakePhoto(TokenForm token)
        {
            UriBuilder uriBuilder = new UriBuilder(Program.ServerUrl);

            uriBuilder.Path  = "/api/photos";
            uriBuilder.Query = "tokenid=" + token.tokenid;

            if (ModelState.IsValid)
            {
                Console.WriteLine("Received hsid: " + token.tokenid);

                Task <Vector> CaptureImageAsync = Task.Run <Vector>(() => CaptureImage());
                Vector        image             = await CaptureImageAsync;

                HttpClient          httpClient = new HttpClient();
                HttpResponseMessage response   = await httpClient.PostAsync(uriBuilder.Uri,
                                                                            new ByteArrayContent((byte [])image.get_BinaryData()));

                if (response.IsSuccessStatusCode)
                {
                    EntityIdResponse scan = await response.Content.ReadAsAsync <EntityIdResponse>();

                    return(Created(response.Headers.Location, scan));
                }
                else
                {
                    return(InternalServerError(new ServerResponseError(response)));
                }
            }
            else
            {
                return(BadRequest("Expected hsid"));
            }
        }
Esempio n. 3
0
 public Token(TokenType type, TokenForm form, dynamic value, int line, int location)
 {
     Type     = type;
     Form     = form;
     Value    = value;
     Line     = line;
     Location = location;
 }
Esempio n. 4
0
        // [EnableCors("AllowSpecificOrigin")]
        // [DisableCors]
        public async Task Token([FromBody] TokenForm form)
        {
            Console.WriteLine(form.Password);
            var username = form.Email;    // Request.Form["username"];
            var password = form.Password; // Request.Form["password"];

            var identity = GetIdentity(username, password);

            if (identity == null)
            {
                Response.StatusCode = 400;
                await Response.WriteAsync("Invalid username or password.");

                return;
            }

            var now = DateTime.UtcNow;
                        // создаем JWT-токен
            string encodedJwt = null;

            try
            {
                // Console.WriteLine(identity.Name);
                var jwt = new JwtSecurityToken(
                    issuer: AuthOptions.ISSUER,
                    audience: AuthOptions.AUDIENCE,
                    notBefore: now,
                    claims: identity.Claims,
                    expires: now.Add(TimeSpan.FromMinutes(AuthOptions.LIFETIME)),
                    signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256));

                encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Person person   = GetPersonByClaims(identity);
            var    response = new
            {
                access_token = encodedJwt,
                email        = identity.Name,
                tokens       = person.Tokens,
                url          = person.PersonalUrl,
                registers    = person.Registers,
                commission   = person.Commision
            };

            // сериализация ответа
            Response.ContentType = "application/json";
            await Response.WriteAsync(JsonConvert.SerializeObject(response, new JsonSerializerSettings {
                Formatting = Formatting.Indented
            }));
        }
Esempio n. 5
0
        public async Task <ActionResult <DebugSymbolOfferResponse> > FinishUpload([Required][FromBody] TokenForm request)
        {
            if (!remoteStorage.Configured)
            {
                throw new HttpResponseException()
                      {
                          Status = StatusCodes.Status500InternalServerError,
                          Value  = "Remote storage is not configured"
                      };
            }

            var decodedToken = StorageUploadVerifyToken.TryToLoadFromString(dataProtector, request.Token);

            if (decodedToken == null || decodedToken.ParentId == null)
            {
                return(BadRequest("Invalid finished upload token"));
            }

            StorageFile file;

            try
            {
                file = await remoteStorage.HandleFinishedUploadToken(database, decodedToken);
            }
            catch (Exception e)
            {
                logger.LogWarning(e, "Failed to check upload token / resulting file");
                return(BadRequest("Failed to verify that uploaded file is valid"));
            }

            // This is used in the token here to store the devbuild ID
            var symbol = await database.DebugSymbols.FindAsync(decodedToken.ParentId.Value);

            if (symbol == null)
            {
                return(BadRequest("No symbol found with the id in the token"));
            }

            // Mark it as ready to use for stackwalk operations happening in the future
            symbol.Active   = true;
            symbol.Uploaded = true;
            symbol.BumpUpdatedAt();

            await remoteStorage.PerformFileUploadSuccessActions(file, database);

            await database.SaveChangesAsync();

            logger.LogInformation("DebugSymbol {Id} ({StoragePath}) is now uploaded", symbol.Id, file.StoragePath);

            return(Ok());
        }
Esempio n. 6
0
    // Start is called before the first frame update
    IEnumerator LoginEnumerator(string username, string password)
    {
        var login = new LoginForm(username, password);
        var f     = JsonUtility.ToJson(login);
        var bytes = System.Text.Encoding.UTF8.GetBytes(f);

        Debug.Log(f);
        //74 65 73 74 33 e2 80 8b
        //74 65 73 74 33
        yield return(RequestController.PostRequestWorkaround("authentication/login", bytes, ""));

        string jsonCode = RequestController.GetResponseData();

        try
        {
            code = JsonUtility.FromJson <Code>(jsonCode).code;
        }
        catch
        {
            Debug.LogWarning("Failed to login");
            yield break;
        }

        //WWWForm tokenForm = new WWWForm();
        // tokenForm.AddField("grantType", "authorization_code");
        //tokenForm.AddField("code", code);
        TokenForm t          = new TokenForm("authorization_code", code);
        var       tok        = JsonUtility.ToJson(t);
        var       tokenBytes = System.Text.Encoding.UTF8.GetBytes(tok);

        yield return(RequestController.PostRequestWorkaround("token", tokenBytes, ""));

        string jsonToken = RequestController.GetResponseData();

        accessToken = JsonUtility.FromJson <Token>(jsonToken).accessToken;

        todoList.SetActive(true);
        mainMenu.SetActive(false);
        SessionController.SetAccessToken(accessToken);



        yield return(sessionController.GetLists());

        UISystem.instance.GenerateTaskLists();
        yield return(sessionController.GetAllTasks());

        UISystem.instance.MapTasksToLists();
    }
Esempio n. 7
0
        public async Task <IHttpActionResult> PostFingerprintsScans(TokenForm token)
        {
            if (ModelState.IsValid)
            {
                if (token == null)
                {
                    Console.WriteLine("Token not received. Signal the error and stop processing request.");
                    return(BadRequest("Expected tokenid"));
                }
                else
                {
                    Console.WriteLine("Received tokenid: " + token.tokenid);
                    var response = await scanningService.PostFingerprintScan(token.tokenid);

                    return(Created(response.FingerprintLocaltion, response.FingerprintId));
                }
            }
            else
            {
                return(BadRequest("Expected tokenid"));
            }
        }