Answer the question
In order to leave comments, you need to log in
How to do authentication in a modern web application?
If the web application is supposed to have the following architecture:
Backend: api written in Go.
Client: Static JavaScript pages that access the backend API.
How is authentication done in such applications?
How to do primary authentication?
Do I understand correctly that each time the API is accessed on the backend, it is necessary to check whether the user is authenticated or not. How should it be done?
Answer the question
In order to leave comments, you need to log in
As an everywhere:
make an authorization method. For example
Which takes parameters
{
"login":"",
"email":"", //необязательно но я использую
"pass":""
}
rb := make([]byte, 64)
_, err := rand.Read(rb)
if err != nil {
log.Print(err)
}
var token string = `{
"user_id":"",
"name":"",
...,
"salt": "`+base64.URLEncoding.EncodeToString(rb)+`",
"expiries":"", //время жизни токена
}`
encrypt_data := xxtea.Encrypt([]byte(token), []byte("Ваш ключ для шифровки токена"))
return base64.URLEncoding.EncodeToString(encrypt_data)
Do I understand correctly that each time the API is accessed on the backend, it is necessary to check whether the user is authenticated or not.That's right, it's a must.
How should it be done?Depending on the authorization method. For example cookies, session.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question