chore: update access token order
This commit is contained in:
parent
ad3487a9ac
commit
745902e8b1
2 changed files with 9 additions and 8 deletions
|
|
@ -36,15 +36,15 @@ func extractTokenFromHeader(c echo.Context) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func findAccessToken(c echo.Context) string {
|
func findAccessToken(c echo.Context) string {
|
||||||
accessToken := ""
|
// Check the HTTP request header first.
|
||||||
cookie, _ := c.Cookie(auth.AccessTokenCookieName)
|
accessToken, _ := extractTokenFromHeader(c)
|
||||||
if cookie != nil {
|
|
||||||
accessToken = cookie.Value
|
|
||||||
}
|
|
||||||
if accessToken == "" {
|
if accessToken == "" {
|
||||||
accessToken, _ = extractTokenFromHeader(c)
|
// Check the cookie.
|
||||||
|
cookie, _ := c.Cookie(auth.AccessTokenCookieName)
|
||||||
|
if cookie != nil {
|
||||||
|
accessToken = cookie.Value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return accessToken
|
return accessToken
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ func (in *GRPCAuthInterceptor) authenticate(ctx context.Context, accessToken str
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTokenFromMetadata(md metadata.MD) (string, error) {
|
func getTokenFromMetadata(md metadata.MD) (string, error) {
|
||||||
|
// Check the HTTP request header first.
|
||||||
authorizationHeaders := md.Get("Authorization")
|
authorizationHeaders := md.Get("Authorization")
|
||||||
if len(md.Get("Authorization")) > 0 {
|
if len(md.Get("Authorization")) > 0 {
|
||||||
authHeaderParts := strings.Fields(authorizationHeaders[0])
|
authHeaderParts := strings.Fields(authorizationHeaders[0])
|
||||||
|
|
@ -135,7 +136,7 @@ func getTokenFromMetadata(md metadata.MD) (string, error) {
|
||||||
}
|
}
|
||||||
return authHeaderParts[1], nil
|
return authHeaderParts[1], nil
|
||||||
}
|
}
|
||||||
// check the HTTP cookie
|
// Check the cookie header.
|
||||||
var accessToken string
|
var accessToken string
|
||||||
for _, t := range append(md.Get("grpcgateway-cookie"), md.Get("cookie")...) {
|
for _, t := range append(md.Get("grpcgateway-cookie"), md.Get("cookie")...) {
|
||||||
header := http.Header{}
|
header := http.Header{}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue