Sobes.tech
Junior — Middle

What methods of authorization have you used in your projects?

sobes.tech AI

Answer from AI

In projects on Go, I used several authentication methods:

  • JWT (JSON Web Tokens) — a popular stateless authentication method where the client receives a token after login and sends it in request headers.
  • Basic Auth — a simple method transmitting login and password in the HTTP header, suitable for internal or simple services.
  • OAuth 2.0 — for integration with external authorization providers (Google, Facebook, etc.), often through libraries.

Example of using JWT in Go with the github.com/dgrijalva/jwt-go library:

import (
    "github.com/dgrijalva/jwt-go"
    "time"
)

func GenerateJWT(secret []byte, userID string) (string, error) {
    token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
        "user_id": userID,
        "exp":    time.Now().Add(time.Hour * 72).Unix(),
    })
    return token.SignedString(secret)
}

The choice of method depends on security requirements and application architecture.

What methods of authorization have you used in your… - sobes.tech