Skip to content

Conversation

@suzp1984
Copy link
Contributor

@suzp1984 suzp1984 commented Nov 26, 2024

What's the problem of http api authentication?

There are a lot of repeated codes in the http api hander func.

var token string
if err := ParseBody(ctx, r.Body, &struct {
Token *string `json:"token"`
}{
Token: &token,
}); err != nil {
return errors.Wrapf(err, "parse body")
}
apiSecret := envApiSecret()
if err := Authenticate(ctx, apiSecret, token, r.Header); err != nil {
return errors.Wrapf(err, "authenticate")
}

Solution

refactor those token authentication codes to one place.
There are 2 kinds of token verification.

  1. Token in http post body.
    middlewareAuthTokenInBody
  2. Token in url query.
    middlewareAuthTokenInURL
  3. ai-talk.go is an exception, the token authentication depends room token, so keep ai-talk.go.

@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Nov 26, 2024
@suzp1984 suzp1984 force-pushed the refactor/http-handler-middleware branch from dacc034 to c098941 Compare November 26, 2024 12:44
@suzp1984 suzp1984 force-pushed the refactor/http-handler-middleware branch from c098941 to a70326c Compare November 26, 2024 12:52
@suzp1984 suzp1984 marked this pull request as ready for review November 26, 2024 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

EnglishNative This issue is conveyed exclusively in English.

Development

Successfully merging this pull request may close these issues.

2 participants