Swyftey
Swyftey
Explore posts from servers
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
Thank you!
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
in this scenerio, it doesn't, but calling it as a function (instead of making it an endpoint) which then redirects to a url path works
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
In javascript, I basically just made an endpoint called "login-redirect" which is what discord's redirect_uri was set to, and it would execute
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
It's confusing coming from JavaScript I think
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
omg nvm
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
Yes, but that's what "LoginRedirect" was, just with an endpoint, but it was never firing as an endpoint, it works without the endpoint/route assigned to it
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
gotcha
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
Username as in "display name"?
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
If all that happens within the handler, do I need to call this still?
c#

[ApiExplorerSettings(IgnoreApi = true)]
public async Task<IActionResult> LoginRedirect()
{
var result = await HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
if (!result.Succeeded)
{
return Unauthorized();
}
Console.WriteLine("OK");
return Ok();
}
c#

[ApiExplorerSettings(IgnoreApi = true)]
public async Task<IActionResult> LoginRedirect()
{
var result = await HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
if (!result.Succeeded)
{
return Unauthorized();
}
Console.WriteLine("OK");
return Ok();
}
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
Yeah
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
Thanks for the help
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
This was my issue as far as I am aware. I shouldn't have made my own endpoint for the callback URL ("/login-redirect"), it should just be a function/task whatever tf it's considered in c# 😭 .
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
OK. From what I am maybe starting to understand: Do I not need a specific endpoint for the callback url (e.g, "/login-redirect")? I thought I specifically needed to authorize the user (based on the code and state returned), but maybe the oauth package does that for you already?
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
This is what I currently have:
c#
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "Discord";
})
.AddCookie()
.AddDiscord(options =>
{
options.ClientId = builder.Configuration["BotConfiguration:ClientId"];

options.ClientSecret = builder.Configuration["BotConfiguration:ClientSecret"];

options.CallbackPath = "/auth/login-redirect";
options.AuthorizationEndpoint = "https://discord.com/api/oauth2/authorize";

options.TokenEndpoint = "https://discord.com/api/oauth2/token";

options.UserInformationEndpoint = "https://discord.com/api/v10/users/@me";

options.Scope.Add("identify");
options.SaveTokens = true;
});
c#
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "Discord";
})
.AddCookie()
.AddDiscord(options =>
{
options.ClientId = builder.Configuration["BotConfiguration:ClientId"];

options.ClientSecret = builder.Configuration["BotConfiguration:ClientSecret"];

options.CallbackPath = "/auth/login-redirect";
options.AuthorizationEndpoint = "https://discord.com/api/oauth2/authorize";

options.TokenEndpoint = "https://discord.com/api/oauth2/token";

options.UserInformationEndpoint = "https://discord.com/api/v10/users/@me";

options.Scope.Add("identify");
options.SaveTokens = true;
});
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
I'm afraid that if I use the package you sent, it will possibly be the same issue.
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
Thank you for this! Out of curiosity, what is the difference between the package you sent and the package I am currently using (AspNet.Security.OAuth.Discord)?
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
Sorry, I’m really new to C#/asp.net, I don’t think I have an OAuth handler currently.
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
Hi. Sorry for the late reply! I am currently not at my computer, but the middleware setup is close to the default setup Visual Studio provides. I’ll send a screenshot when I can.
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
bump
41 replies
CC#
Created by Swyftey on 9/19/2024 in #help
✅ Discord Authentication Redirection Issue
I feel I'm getting closer and closer to a fix, I think just an example on how this code should look would be really helpful, thanks!
41 replies