Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"message": "unauthorized" #146

Open
wick233 opened this issue Oct 10, 2024 · 8 comments
Open

"message": "unauthorized" #146

wick233 opened this issue Oct 10, 2024 · 8 comments

Comments

@wick233
Copy link

wick233 commented Oct 10, 2024

我在pasteme这个表里面加了个账号,然后post请求/api/v3/token,body里面传了{
"username": "[email protected]",
"password": "123456",
}为什么报错账号或密码错误{
"code": 401,
"message": "incorrect Username or Password"
}

@LucienShui
Copy link
Owner

刚才简单读了下代码,结合我残缺的记忆,好像 是因为现在并没有实质上的账号密码的逻辑,所以会报错。

目前应该只能通过 Nobody 来进行 API 操作。

@wick233
Copy link
Author

wick233 commented Oct 12, 2024

我把那个登录逻辑写成死的账号密码了,在mysql的employee里面加了条数据,这样做应该可以返回token了吧,是不是还需要把前端的自我销毁的按钮的disabled拿掉,然后在项目里面docker build了一下,docker compose up -d了一下,有单独搞了个docker-compose.yml,里面写了version: "3"

services:
pasteme-frontend:
image: pasteme/frontend:3.4.2
container_name: pasteme-frontend
depends_on:
- pasteme-backend
healthcheck:
test: ["CMD", "curl", "-so", "/dev/null", "localhost:8080/usr/config.json"]
interval: 45s
timeout: 3s
retries: 3
restart: always
ports:
- 80:8080
volumes:
- ./data/nginx-logs/:/var/lib/pasteme/
- ./data/frontend-usr/:/www/pasteme/usr/
docker compose up -d 之后,页面打不开,我看了下后端的docker容器状态是unhealthy,现在的问题就是,怎么用我本地打包的后端容器和前端容器配合mysql容器运行起来

@LucienShui
Copy link
Owner

  1. docker logs pasteme-backend 看一下后端的报错是什么?
  2. 你的 MySQL 是部署在宿主机吗?

我理解你这边的诉求是 API 鉴权是吗?可以考虑直接用 HTTP Basic Authentication,这样应该能实现你的需求以及不需要对代码做改动。

@wick233
Copy link
Author

wick233 commented Oct 14, 2024

我把之前的容器都删了,用docker-compose.yml又部署了一下,调了下接口,报错账户名或密码错误,传的账号密码是对的
image
image

@LucienShui
Copy link
Owner

LucienShui commented Oct 14, 2024

https://github.com/PasteUs/PasteMeGoBackend/blob/3ea1b23a9a8be8169cf2380a9fc092e86d4e61f9/handler/token/init.go#L25

func authenticator(c *gin.Context) (interface{}, error) {
	var body user.User
	if err := c.ShouldBind(&body); err != nil {
		return "", jwt.ErrMissingLoginValues
	}

	// TODO login authenticator

	return nil, jwt.ErrFailedAuthentication
}

请问这一行的代码有进行修改吗?目前 main branch 中登录逻辑是未实现的状态。

我理解需要登录的话,这里需要进行更改。

@wick233
Copy link
Author

wick233 commented Oct 14, 2024

https://github.com/PasteUs/PasteMeGoBackend/blob/3ea1b23a9a8be8169cf2380a9fc092e86d4e61f9/handler/token/init.go#L25

func authenticator(c *gin.Context) (interface{}, error) {
	var body user.User
	if err := c.ShouldBind(&body); err != nil {
		return "", jwt.ErrMissingLoginValues
	}

	// TODO login authenticator

	return nil, jwt.ErrFailedAuthentication
}

请问这一行的代码有进行修改吗?目前 main branch 中登录逻辑是未实现的状态。

我理解需要登录的话,这里需要进行更改。

没有修改,因为改完之后,我不知道怎么用本地的镜像去部署,前几天折腾了一下,后端容器状态是unhealthy不能用

@LucienShui
Copy link
Owner

  1. docker logs pasteme-backend 看一下后端的报错是什么?
  2. 你的 MySQL 是部署在宿主机吗?

我理解你这边的诉求是 API 鉴权是吗?可以考虑直接用 HTTP Basic Authentication,这样应该能实现你的需求以及不需要对代码做改动。

@wick233 如果需求是“需要账号密码才能调用 API”,建议直接考虑用 nginx 实现 HTTP Basic Authentication

@wick233
Copy link
Author

wick233 commented Oct 14, 2024

  1. docker logs pasteme-backend 看一下后端的报错是什么?
  2. 你的 MySQL 是部署在宿主机吗?

我理解你这边的诉求是 API 鉴权是吗?可以考虑直接用 HTTP Basic Authentication,这样应该能实现你的需求以及不需要对代码做改动。

@wick233 如果需求是“需要账号密码才能调用 API”,建议直接考虑用 nginx 实现 HTTP Basic Authentication

我的需求是可以创建永久的文档,可以关闭自我销毁按钮

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants