func Identify()

in server/datasource/auth/identify.go [36:56]


func Identify(ctx context.Context) (*rbacmodel.Account, error) {
	claims, err := rbacmodel.FromContext(ctx)
	if err != nil {
		openlog.Error("get account from token failed", openlog.WithErr(err))
		return nil, err
	}
	account, err := rbacmodel.GetAccount(claims)
	if err != nil {
		openlog.Error("get account from claims failed", openlog.WithErr(err))
		return nil, err
	}
	if len(account.Roles) == 0 {
		openlog.Error("no role found in token")
		return nil, rbacmodel.NewError(rbacmodel.ErrNoPermission, "no role found in token")
	}
	err = accountExist(ctx, account.Name)
	if err != nil {
		return nil, err
	}
	return account, nil
}