Dani
Dani
CC#
Created by Dani on 1/4/2025 in #help
most simple form (impossible)
want to do the most basic of basic thing and thats to send a form and get the value of it right now i got this page:
@page "/Register"
@using Microsoft.AspNetCore.Identity
@using System.ComponentModel.DataAnnotations
@using learning.Models

<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3 class="text-center">Register</h3>
<h1>Status: @status</h1>
</div>
<div class="card-body">
<EditForm Model="@registerModel" OnValidSubmit="@HandleValidSubmit" FormName="registerModel">
<DataAnnotationsValidator />
<ValidationSummary />

<div class="form-group">
<label for="email">Email</label>
<InputText class="form-control" @bind-Value="registerModel.Email" />
</div>

<div class="form-group">
<label for="password">Password</label>
<InputText type="password" class="form-control" @bind-Value="registerModel.Password" />
</div>

<div class="form-group">
<label for="confirmPassword">Confirm Password</label>
<InputText type="password" class="form-control" @bind-Value="registerModel.ConfirmPassword" />
</div>

<button type="submit" class="btn btn-primary btn-block mt-3">Register</button>
</EditForm>

<div class="mt-3 text-center">
<a href="/account/login">Already have an account? Login here</a>
</div>
</div>
</div>
</div>
</div>
</div>
@page "/Register"
@using Microsoft.AspNetCore.Identity
@using System.ComponentModel.DataAnnotations
@using learning.Models

<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3 class="text-center">Register</h3>
<h1>Status: @status</h1>
</div>
<div class="card-body">
<EditForm Model="@registerModel" OnValidSubmit="@HandleValidSubmit" FormName="registerModel">
<DataAnnotationsValidator />
<ValidationSummary />

<div class="form-group">
<label for="email">Email</label>
<InputText class="form-control" @bind-Value="registerModel.Email" />
</div>

<div class="form-group">
<label for="password">Password</label>
<InputText type="password" class="form-control" @bind-Value="registerModel.Password" />
</div>

<div class="form-group">
<label for="confirmPassword">Confirm Password</label>
<InputText type="password" class="form-control" @bind-Value="registerModel.ConfirmPassword" />
</div>

<button type="submit" class="btn btn-primary btn-block mt-3">Register</button>
</EditForm>

<div class="mt-3 text-center">
<a href="/account/login">Already have an account? Login here</a>
</div>
</div>
</div>
</div>
</div>
</div>
9 replies
CC#
Created by Dani on 2/26/2024 in #help
get url after oauth2 redirect
hey guys so im working on a api intergration with the blizzard api and blazor server app right now its all going good but im at that point where im stuck when trying to use oauth im making a get request to the authorize server i login with my blizzard account and then i get redirected back to the page in the url with my code needed to make scoped request how can i get this code from the url when the redirected is done?
public async Task<Oauth> GetOauthToken(string ClientId, string Scope, string State, string RedirectUri, string ResponseType)
{
var request = new RestRequest("/authorize", Method.Get);
request.AddParameter("client_id",ClientId);
request.AddParameter("scope",Scope);
request.AddParameter("state",State);
request.AddParameter("redirect_uri",RedirectUri);
request.AddParameter("response_type",ResponseType);

using (var client = new RestClient("https://oauth.battle.net"))
{
var url = client.BuildUri(request).ToString();
await client.ExecuteAsync(request);
return new Oauth
{
AuthorizationCode = url
};

}
}
public async Task<Oauth> GetOauthToken(string ClientId, string Scope, string State, string RedirectUri, string ResponseType)
{
var request = new RestRequest("/authorize", Method.Get);
request.AddParameter("client_id",ClientId);
request.AddParameter("scope",Scope);
request.AddParameter("state",State);
request.AddParameter("redirect_uri",RedirectUri);
request.AddParameter("response_type",ResponseType);

using (var client = new RestClient("https://oauth.battle.net"))
{
var url = client.BuildUri(request).ToString();
await client.ExecuteAsync(request);
return new Oauth
{
AuthorizationCode = url
};

}
}
and on the page it looks like this
private async Task MakeRequest3()
{
try
{
var url = await api.GetOauthToken("clientid", "wow.profile", "/", "https://localhost:7280/", "code");
nav.NavigateTo(url.AuthorizationCode);
}
catch (UnSuccesfullReponseException e)
{
Console.WriteLine(e.Message);
apiOutput = e.Message;
}
}
private async Task MakeRequest3()
{
try
{
var url = await api.GetOauthToken("clientid", "wow.profile", "/", "https://localhost:7280/", "code");
nav.NavigateTo(url.AuthorizationCode);
}
catch (UnSuccesfullReponseException e)
{
Console.WriteLine(e.Message);
apiOutput = e.Message;
}
}
how can i detect when the redirect is succesfull and then get the current url so i can extract the code value from there?
2 replies