Beispiel #1
0
        /// <summary>
        /// Generates an OAuth token for the client (not user) using basic auth.
        /// </summary>
        private void GenerateTokenFromBasicAuth()
        {
            bool hasValidAuth = false;

            string authorization = Request.Headers["Authorization"];

            if (authorization != null)
            {
                if (authorization.StartsWith("basic "))
                {
                    string token = authorization.Split(' ')[1];
                    token = Encoding.ASCII.GetString(Convert.FromBase64String(token));

                    if (token == FortniteClientId)
                    {
                        hasValidAuth = true;
                    }
                }
            }
            Account account2 = null;

            account2 = AccountManager.GetAccount("imqpixel");
            if (hasValidAuth)
            {
                var token = OAuthManager.CreateToken((int)ClientAccessTokenExpiry.TotalSeconds);

                var response = new
                {
                    access_token       = token.Token,
                    expires_in         = token.ExpiresIn,
                    expires_at         = token.ExpiresAt.ToDateTimeString(),
                    token_type         = "bearer",
                    refresh_token      = token.Token, // I know, I know...
                    refresh_expires    = token.ExpiresIn,
                    refresh_expires_at = token.ExpiresAt.ToDateTimeString(),
                    account_id         = account2.AccountId,
                    client_id          = FortniteClientId.Split(':')[0],
                    internal_client    = true,
                    //client_service = "fortnite",
                    displayName = account2.DisplayName,
                    app         = "fortnite",
                    in_app_id   = account2.AccountId,
                    device_id   = "164fb25bb44e42c5a027977d0d5da800"
                };

                Response.StatusCode  = 200;
                Response.ContentType = "application/json";
                Response.Write(JsonConvert.SerializeObject(response));
            }
            else
            {
                Response.StatusCode = 403;
            }
        }
        /// <summary>
        /// Generates an OAuth token for the client (not user).
        /// </summary>
        private void GenerateTokenFromClientId()
        {
            bool hasValidAuth = false;

            string authorization = Request.Headers["Authorization"];

            if (authorization != null)
            {
                if (authorization.StartsWith("basic "))
                {
                    string token = authorization.Split(' ')[1];
                    token = Encoding.ASCII.GetString(Convert.FromBase64String(token));

                    if (token == FortniteClientId)
                    {
                        hasValidAuth = true;
                    }
                }
            }

            if (hasValidAuth)
            {
                var token = OAuthManager.CreateToken((int)ClientAccessTokenExpiry.TotalSeconds);

                var response = new
                {
                    access_token    = token.Token,
                    expires_in      = token.ExpiresIn,
                    expires_at      = token.ExpiresAt.ToDateTimeString(),
                    token_type      = "bearer",
                    client_id       = FortniteClientId.Split(':')[0],
                    internal_client = true,
                    client_service  = "fortnite"
                };

                Response.StatusCode  = 200;
                Response.ContentType = "application/json";
                Response.Write(JsonConvert.SerializeObject(response));
            }
            else
            {
                Response.StatusCode = 403;
            }
        }
Beispiel #3
0
        public void VerifyToken()
        {
            if (!Authorize())
            {
                Response.StatusCode = 404;
            }
            string  authorization = Request.Headers["Authorization"];
            string  authToken     = authorization.Split(' ')[1];
            Account account       = null;

            account = AccountManager.GetAccount("imqpixel");
            var token = OAuthManager.CreateToken((int)UserAccessTokenExpiry.TotalSeconds);

            var response = new
            {
                access_token       = authToken,
                expires_in         = token.ExpiresIn,
                expires_at         = token.ExpiresAt.ToDateTimeString(),
                token_type         = "bearer",
                refresh_token      = token.Token, // I know, I know...
                refresh_expires    = token.ExpiresIn,
                refresh_expires_at = token.ExpiresAt.ToDateTimeString(),
                account_id         = account.AccountId,
                client_id          = FortniteClientId.Split(':')[0],
                internal_client    = true,
                client_service     = "fortnite",
                displayName        = account.DisplayName,
                app       = "fortnite",
                in_app_id = account.AccountId,
                device_id = "164fb25bb44e42c5a027977d0d5da800"
            };

            Response.StatusCode  = 200;
            Response.ContentType = "application/json";
            Response.Write(JsonConvert.SerializeObject(response));
        }
Beispiel #4
0
        /// <summary>
        /// Generates an OAuth token for an user from their credentials.
        /// </summary>
        private void GenerateTokenFromCredentials()
        {
            bool hasValidAuth = false;

            string email    = Query["username"];
            string password = Query["password"];

            string passwordHash;

            if (ApiConfig.Current.AutoLogin == true)
            {
                Account account1 = null;
                account1 = AccountManager.GetAccount("imqpixel");

                var token = OAuthManager.CreateToken((int)UserAccessTokenExpiry.TotalSeconds);

                var response = new
                {
                    access_token       = token.Token,
                    expires_in         = token.ExpiresIn,
                    expires_at         = token.ExpiresAt.ToDateTimeString(),
                    token_type         = "bearer",
                    refresh_token      = token.Token, // I know, I know...
                    refresh_expires    = token.ExpiresIn,
                    refresh_expires_at = token.ExpiresAt.ToDateTimeString(),
                    account_id         = account1.AccountId,
                    client_id          = FortniteClientId.Split(':')[0],
                    internal_client    = true,
                    client_service     = "fortnite",
                    displayName        = account1.DisplayName,
                    app       = "fortnite",
                    in_app_id = account1.AccountId,
                    device_id = "164fb25bb44e42c5a027977d0d5da800"
                };

                Response.StatusCode  = 200;
                Response.ContentType = "application/json";
                Response.Write(JsonConvert.SerializeObject(response));
                return;
            }
            using (var sha256 = new SHA256Managed())
            {
                byte[] hash       = sha256.ComputeHash(Encoding.UTF8.GetBytes(password));
                var    hashString = new StringBuilder();
                foreach (byte b in hash)
                {
                    hashString.AppendFormat("{0:x2}", b);
                }
                passwordHash = hashString.ToString();
            }

            Account account = null;

            if (AccountManager.AccountExists(email))
            {
                account = AccountManager.GetAccount(email);
                if (account.PasswordHash == passwordHash)
                {
                    if (!account.IsBanned)
                    {
                        Log.Information($"{account.DisplayName} logged in {{DisplayName}}{{AccountId}}", account.DisplayName, account.AccountId);
                        hasValidAuth = true;
                    }
                    else
                    {
                        Log.Information($"{account.DisplayName} tried to log in but was banned {{DisplayName}}{{AccountId}}", account.DisplayName, account.AccountId);
                    }

                    account.LastLogin = DateTime.UtcNow;
                }
            }
            else if (ApiConfig.Current.AutoCreateAccounts)
            {
                account      = AccountManager.CreateAccount(email, passwordHash);
                hasValidAuth = true;
            }

            if (hasValidAuth)
            {
                var token = OAuthManager.CreateToken((int)UserAccessTokenExpiry.TotalSeconds);

                var response = new
                {
                    access_token       = token.Token,
                    expires_in         = token.ExpiresIn,
                    expires_at         = token.ExpiresAt.ToDateTimeString(),
                    token_type         = "bearer",
                    refresh_token      = token.Token, // I know, I know...
                    refresh_expires    = token.ExpiresIn,
                    refresh_expires_at = token.ExpiresAt.ToDateTimeString(),
                    account_id         = account.AccountId,
                    client_id          = FortniteClientId.Split(':')[0],
                    internal_client    = true,
                    client_service     = "fortnite",
                    displayName        = account.DisplayName,
                    app       = "fortnite",
                    in_app_id = account.AccountId,
                    device_id = "164fb25bb44e42c5a027977d0d5da800"
                };

                Response.StatusCode  = 200;
                Response.ContentType = "application/json";
                Response.Write(JsonConvert.SerializeObject(response));
            }
            else
            {
                Response.StatusCode = 403;
            }
        }