Skip to content

Commit

Permalink
fix(authentication): change login api url (#414)
Browse files Browse the repository at this point in the history
* fix(authentication): change manager API login path

* fix(authentication): change authentication unit test

* fix(authentication): clean nginx.conf codes

* fix(authentication): change login URL of front end

* fix(authentication): change authentication filter rule
  • Loading branch information
bzp2010 authored Aug 26, 2020
1 parent d37c11b commit 9a2cd71
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/filter/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

func Authentication() gin.HandlerFunc {
return func(c *gin.Context) {
if c.Request.URL.Path != "/user/login" && strings.HasPrefix(c.Request.URL.Path,"/apisix") {
if c.Request.URL.Path != "/apisix/admin/user/login" && strings.HasPrefix(c.Request.URL.Path,"/apisix") {
tokenStr := c.GetHeader("Authorization")

// verify token
Expand Down
2 changes: 1 addition & 1 deletion api/route/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type UserSession struct {
}

func AppendAuthentication(r *gin.Engine) *gin.Engine {
r.POST("/user/login", userLogin)
r.POST("/apisix/admin/user/login", userLogin)
return r
}

Expand Down
4 changes: 2 additions & 2 deletions api/route/authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var token string
func TestUserLogin(t *testing.T) {
// password error
handler.
Post("/user/login").
Post("/apisix/admin/user/login").
Header("Content-Type", "application/x-www-form-urlencoded").
Body("username=admin&password=admin1").
Expect(t).
Expand All @@ -37,7 +37,7 @@ func TestUserLogin(t *testing.T) {

// login success
sessionResponse := handler.
Post("/user/login").
Post("/apisix/admin/user/login").
Header("Content-Type", "application/x-www-form-urlencoded").
Body("username=admin&password=admin").
Expect(t).
Expand Down
7 changes: 0 additions & 7 deletions compose/dashboard_conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ server {
try_files $uri $uri/ /index.html;
}

location /user/login {
if ( $request_method = 'POST' ) { #HERE
proxy_pass http://manager:8080;
}
try_files $uri $uri/ /index.html;
}

location /apisix/admin {
proxy_pass http://manager:8080/apisix/admin;
}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/User/components/LoginMethodPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const LoginMethodPassword: UserModule.LoginMethod = {
submit: async (data) => {
if (data.username !== '' && data.password !== '') {
try {
const result = await request('/user/login', {
const result = await request('/apisix/admin/user/login', {
method: 'POST',
requestType: 'form',
prefix: '',
Expand Down Expand Up @@ -127,7 +127,6 @@ const LoginMethodPassword: UserModule.LoginMethod = {
}
},
logout: () => {
console.log('password logout');
localStorage.removeItem('token');
},
};
Expand Down

0 comments on commit 9a2cd71

Please sign in to comment.