uselessxp
uselessxp
CC#
Created by uselessxp on 3/22/2024 in #help
Selenium wait for the page to load completely
For some reason looks like that the implicit way:
private void button2_Click(object sender, EventArgs e)
{
driver.Url = "https://mywebsiste.com/login";

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

driver.FindElement(By.Id("username")).SendKeys("myusername");
driver.FindElement(By.Id("password")).SendKeys("mypassword");
driver.FindElement(By.ClassName("remember")).Click();
driver.FindElement(By.Id("loginSubmit")).Click();
}
private void button2_Click(object sender, EventArgs e)
{
driver.Url = "https://mywebsiste.com/login";

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

driver.FindElement(By.Id("username")).SendKeys("myusername");
driver.FindElement(By.Id("password")).SendKeys("mypassword");
driver.FindElement(By.ClassName("remember")).Click();
driver.FindElement(By.Id("loginSubmit")).Click();
}
Works perfectly, also if I don't have idea about how I randomly decited to use this method, for go on, thinking that driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); just add a 10 seconds pause before execute next commands, but looks like that this one "wait max 10 seconds" but if he can't perform operations before, it do it So I suppose that it automatically handle the situation
2 replies
CC#
Created by uselessxp on 4/7/2023 in #help
❔ Implement JWT to my WebAPI .NET 7.0 project - First time
Well, now I created a Post method for login in one of my controllers, I don't know if I have to create a custom class for this, or what, maybe yes, I guess something like Auth controller with this Post method, I wait confirmation. For the moment I pasted this code in one of my existing controllers for try it:
[HttpPost("login")]
public IActionResult Login([FromBody] LoginRequest login)
{
if (login == null)
{
return BadRequest("Invalid client request");
}

// temporary fake login
if (login.Username == "TestUser" && login.Password == "TestPwd")
{
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.ASCII.GetBytes(_config["Jwt:Key"]);
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new Claim[]
{
new Claim(ClaimTypes.Name, login.Username)
}),
Expires = DateTime.UtcNow.AddMinutes(30),
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
};
var token = tokenHandler.CreateToken(tokenDescriptor);
var tokenString = tokenHandler.WriteToken(token);

return Ok(new { Token = tokenString });
}
else
{
return Unauthorized();
}
}

private string GenerateJwtToken(string username)
{
return "sample_token";
}

public class LoginRequest
{
public string Username { get; set; }
public string Password { get; set; }
}
[HttpPost("login")]
public IActionResult Login([FromBody] LoginRequest login)
{
if (login == null)
{
return BadRequest("Invalid client request");
}

// temporary fake login
if (login.Username == "TestUser" && login.Password == "TestPwd")
{
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.ASCII.GetBytes(_config["Jwt:Key"]);
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new Claim[]
{
new Claim(ClaimTypes.Name, login.Username)
}),
Expires = DateTime.UtcNow.AddMinutes(30),
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
};
var token = tokenHandler.CreateToken(tokenDescriptor);
var tokenString = tokenHandler.WriteToken(token);

return Ok(new { Token = tokenString });
}
else
{
return Unauthorized();
}
}

private string GenerateJwtToken(string username)
{
return "sample_token";
}

public class LoginRequest
{
public string Username { get; set; }
public string Password { get; set; }
}
I found this code on web, and I adapted it by changing the login system, and creating a fake login for now. It seems all clear, only I don't understand the GenerateJwtToken method, if I'm not wrong it's never called. Forgot to say that's before the GenerateJwpToken method snippet, is written that I have to implement JWT token logic without further explainations.
10 replies
CC#
Created by uselessxp on 4/7/2023 in #help
❔ Implement JWT to my WebAPI .NET 7.0 project - First time
now I added this in my appsettings.json
"Jwt": {
"Key": "mySecretKey123",
"Issuer": "myIssuer",
"Audience": "myAudience"
},
"Jwt": {
"Key": "mySecretKey123",
"Issuer": "myIssuer",
"Audience": "myAudience"
},
10 replies
CC#
Created by uselessxp on 4/7/2023 in #help
❔ Implement JWT to my WebAPI .NET 7.0 project - First time
I'm really confused about next steps as every guide show different things to do
10 replies
CC#
Created by uselessxp on 4/7/2023 in #help
❔ Implement JWT to my WebAPI .NET 7.0 project - First time
yeah, I added some code to my Program.cs Below the code I added for now:
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using System.Security.Cryptography.X509Certificates;

// Configure JWT authentication
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = false, // I put false cause I don't have a domain, am I wrong?
ValidateAudience = false, // I put false cause I don't have a domain, am I wrong?
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = configuration["Jwt:Issuer"],
ValidAudience = configuration["Jwt:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"]))
};
});

// Enable authentication middleware
app.UseAuthentication();
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using System.Security.Cryptography.X509Certificates;

// Configure JWT authentication
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = false, // I put false cause I don't have a domain, am I wrong?
ValidateAudience = false, // I put false cause I don't have a domain, am I wrong?
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = configuration["Jwt:Issuer"],
ValidAudience = configuration["Jwt:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"]))
};
});

// Enable authentication middleware
app.UseAuthentication();
10 replies
CC#
Created by uselessxp on 3/31/2023 in #help
❔ WebAPI Cors problem when calling API from Frontend
yeah actually I did both, and tried to execute with F11, but still not working
9 replies
CC#
Created by uselessxp on 3/31/2023 in #help
❔ WebAPI Cors problem when calling API from Frontend
hm, I added it but still same error
9 replies
CC#
Created by uselessxp on 3/31/2023 in #help
❔ WebAPI Cors problem when calling API from Frontend
bump
9 replies
CC#
Created by uselessxp on 3/24/2023 in #help
❔ C# WebAPI - how to make a field 'optional' ?
Oh, damn it was easier than expected. I left just it without the ? for avoid blank request, but I didn't mind good. Regarding the inside code I think it should works good, only one thing, for some reason, yeah obvious reason, if all fields are sent in blank, the output will be all elements. Which could be a proper way to make sure that at least one field is sent? Could an if with multiple condition works? that maybe return some response code.
if (dbId == null && userId == null && fromDate == null && toDate == null && string.IsNullOrEmpty(username))
{
return BadRequest("You have to type at lest one field!");
}
if (dbId == null && userId == null && fromDate == null && toDate == null && string.IsNullOrEmpty(username))
{
return BadRequest("You have to type at lest one field!");
}
Actually I did in in this way and it seems working, idk if is there a more elegant way to write the code. Now I'm just wondering if I could go on or if I should add some other code in order to get it more efficient.
4 replies
CC#
Created by uselessxp on 2/26/2023 in #help
❔ ✅ send notification on an iPhone
ok it seems it works, I'll add it to my bookmarks, and I hope this app won't get removed as often happen to apple store apps 😠
24 replies
CC#
Created by uselessxp on 2/26/2023 in #help
❔ ✅ send notification on an iPhone
tmrw I'll try to implement it instead of the Telegram Bot that was a bit complex to understand
24 replies
CC#
Created by uselessxp on 2/26/2023 in #help
❔ ✅ send notification on an iPhone
oh ok
24 replies
CC#
Created by uselessxp on 2/26/2023 in #help
❔ ✅ send notification on an iPhone
what do you mean not from C#?
24 replies
CC#
Created by uselessxp on 2/26/2023 in #help
❔ ✅ send notification on an iPhone
but I think this Pushover is similar to Pushbullet but it seems it works also for iOS awesome
24 replies
CC#
Created by uselessxp on 2/26/2023 in #help
❔ ✅ send notification on an iPhone
yeah I'm looking for something that send a push notification or whatever on my iPhone, at the moment I solved by using a TelegramBot that send a message to me since all solutions I found were only for Android :/
24 replies