コード例 #1
0
        public async Task <IActionResult> VerifyToken(PlayerJwtTokenModel playerJwtTokenModel)
        {
            //Check parameters
            if (playerJwtTokenModel == null)
            {
                return(BadRequest("Token blev ikke fundet"));
            }
            if (playerJwtTokenModel.JwtToken == null)
            {
                return(BadRequest("Token blev ikke fundet"));
            }

            try
            {
                //Check if account is logged in
                var account = await _accountService.VerifyToken(playerJwtTokenModel.JwtToken);

                if (account != null)
                {
                    return(Ok(account));
                }
            }
            catch (Exception)
            {
                return(BadRequest("Der skete en fejl under verificering af token"));
            }

            return(BadRequest("Der skete en fejl under verificering af token"));
        }
コード例 #2
0
        public async void Initialize()
        {
            //Login and save JWTToken for later use
            var request = WebRequest.CreateHttp(new Uri(baseUrl + "Account/signin"));

            request.ContentType = "application/json";
            request.Timeout     = 10000;
            request.Method      = "POST";

            //get bytes of the json representation of the payload object and set the payload size
            byte[] bytes =
                Encoding.UTF8.GetBytes(
                    JsonConvert.SerializeObject(new PlayerSignIn("api", "tc5mAM!NIRDp%dr5", "127.0.0.1")));
            request.ContentLength = bytes.Length;

            //write&flush content to the uri endpoint
            using (Stream s = await request.GetRequestStreamAsync().ConfigureAwait(false))
            {
                await s.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);

                await s.FlushAsync().ConfigureAwait(false);

                //close stream
                s.Close();
            }

            //Wait for response for the post request
            var response       = (HttpWebResponse)request.GetResponse();
            var streamResponse = new StreamReader(response.GetResponseStream());

            //Get token from api call
            playerJwtTokenModel =
                JsonConvert.DeserializeObject <PlayerJwtTokenModel>(await streamResponse.ReadToEndAsync());

            streamResponse.Dispose();

            //get game types
            //create a new http request
            request             = WebRequest.CreateHttp(new Uri(baseUrl + "GameType/simple"));
            request.ContentType = "application/json";
            request.Timeout     = 10000;
            request.Method      = "GET";

            var                  gametypeRes = request.GetResponse();
            StreamReader         reader      = new StreamReader(gametypeRes.GetResponseStream());
            IList <GameTypeData> jsonRes     = JsonConvert.DeserializeObject <List <GameTypeData> >(reader.ReadToEnd());

            reader.Dispose();

            foreach (GameTypeData gameType in jsonRes)
            {
                AddGameType(gameType);
            }
        }
コード例 #3
0
        /// <summary>
        /// Calls The API to verify the Player
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <PlayerVerificationResponseModel> VerifyToken(string token)
        {
            PlayerJwtTokenModel jwtTokenModel = new PlayerJwtTokenModel(token);
            var stringContent = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(jwtTokenModel), Encoding.UTF8, "application/json");

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage response =
                    await client.PostAsync(validationRequestURL, stringContent).ConfigureAwait(false);

                stringContent.Dispose();

                using (HttpContent content = response.Content)
                {
                    string jsonString = await content.ReadAsStringAsync().ConfigureAwait(false);

                    return(Newtonsoft.Json.JsonConvert.DeserializeObject <PlayerVerificationResponseModel>(jsonString));
                }
            }
        }