Hej. siedzę sobie nad próbną aplikacją webową. Front-end w Angularze 10, back-end w ASP.NET Core 2.2. Mam małą zagwozdkę. Do końca nie rozumiem co powinno się stać dalej z tokenem autentykacji?
Dla przykładu, w aplikacji klienta wołam API które mi zwraca:
JwtSecurityToken token = new JwtSecurityToken(
issuer: _configuration["Auth:JsonWebToken:Issuer"],
audience: _configuration["Auth:JsonWebToken:Audience"], claims: claims, notBefore: now,
expires: now.Add(TimeSpan.FromMinutes(tokenExpirationMins)), signingCredentials: new SigningCredentials( issuerSigningKey, SecurityAlgorithms.HmacSha256));
string encodedToken = new JwtSecurityTokenHandler().WriteToken(token);
// build & return the response
TokenResponseViewModel response = new TokenResponseViewModel()
{
Token = encodedToken,
Expiration = tokenExpirationMins,
Email = user.Email,
User = user.UserName
};
return Json(response);
I tu jest wszystko jasne, wszystko jest ok. W dalszej części mogę się odpytywać auth.service.ts o to czy użytkownik jest zalogowany, który użytkownik jest zalogowany, mogę też się dowiedzieć jaki jest token zalogowanego użytkownika:
// Retrieves the auth JSON object (or NULL if none)
getAuth(): TokenResponse | null {
if (isPlatformBrowser(this.platformId)) {
var i = localStorage.getItem(this.authKey);
if (i) {
return JSON.parse(i);
}
}
return null;
}
// Returns TRUE if the user is logged in, FALSE otherwise.
isLoggedIn(): boolean {
if (isPlatformBrowser(this.platformId)) {
return localStorage.getItem(this.authKey) != null;
}
return false;
}
Gdzie token.response.ts model wygląda tak:
export interface TokenResponse {
token: string,
expiration: number,
email: string,
user: string
}
Do końca nie jestem pewien jak mogę wykorzystać token: string
?? Jak mogę dalej go wykorzystać komunikując się z API?