Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
Angular authentication with ASP.NET Web Api

I need to build an Authentication between my Angular frontend and ASP.NET Web Api backend.

The requirements are:

  • I need 2 different login pages (1 with a classic login screen and 1 one with a classic login screen + LinkedIn)

I can't find any up to date documentation about how I should make this... I looked to https://auth0.com/ but they are using a package that isn't supported any more by my web api version.

My research also learned me that I probably should use Jwt, but i'm having a difficult time to build this in my web api.

Can someone please give me proper documentation? I know there is a build-in authentication but I don't know how good this one is and how you should use them with JWT. Everything I find on the web is out-of-date... .

Your help is much appreciated.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This is the flow you need to do in order to authenticate a user with linkedin:
Angular Part:
1.redirect the user with the requested query params, for example:

                   var req = {
                    response_type: "code",
                    client_id: "Your Client ID",
                    redirect_uri: location.origin + location.pathname,
                    state: "DCESFWf45A53sdfKef434"
                };
                window.location.href = linkedinAuthorizationUrl + ObjecttoParams(req);

2.After the user is authenticated linkedin will redirect the user back to your redirect_url with additional query param named code, your angular controller should collect it and send it to your webapi method for the next step.
WebApi part:
3.Once you posted the linkedin code to your webapi you need to exchange token with linkedin api(HTTP POST), for example:

using (WebClient wc = new WebClient()){
string RedirectUrl = providerLogin.RedirectUrl;
//Exchange tokens with linkedin                    
byte[] resultAsBytes = 
wc.UploadValues("https://www.linkedin.com/oauth/v2/accessToken", new 
NameValueCollection()
              {
              { "grant_type", "authorization_code" },
              { "code", "THE CODE YOU RECEIVED FROM THE CLIENT" },
              {"redirect_uri",RedirectUrl },
              {"client_id", "YOUR LINKEDIN KEY"},
               {"client_secret", "YOUR LINKEDIN PASSWORD"}
                       });

 string resultAsString = 
 System.Text.Encoding.UTF8.GetString(resultAsBytes);
                        var resultAsJson = JObject.Parse(resultAsString);
                        string accessToken = 
 resultAsJson["access_token"].ToString();
 }

4.Last part - when you have the access token you need to perform GET request to linkedin's API in order to get the user's details:

using (WebClient wc = new WebClient()){
wc.Headers.Add("Authorization", "Bearer " + accessToken);
var json = wc.DownloadString("https://api.linkedin.com/v1/people/~:
(email-address,id,first-name,last-name,picture-url,public-profile-url)?
format=json");
resultAsJson = JObject.Parse(json);
}

And that's it! I hope everything is clear and you understand my code. Good luck!

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda