The Things Network LoRaWAN Stack V3 学习笔记 2.2 使用 CLI 进行 OAuth 登录

前言

在上一篇笔记中已经将 Stack 运行起来了,现在可以着手用 CLI 来做一些测试,第一步是要先登录账户。

小能手这段时间在学习 The Things Network LoRaWAN Stack V3,从使用和代码等角度对该 Stack 进行了分析,详细可点此查看

1 获取 OAUTH 链接

# ./ttn-lw-cli login --callback=false
  INFO Opening your browser on https://localhost:8885/oauth/authorize?client_id=cli&redirect_uri=code&response_type=code
  WARN Could not open your browser, you'll have to go there yourself error=exec: "xdg-open": executable file not found in $PATH
  INFO After logging in and authorizing the CLI, we'll get an access token for future commands.
  INFO Please paste the authorization code and press enter
> 

If you run this command on a remote machine, pass --callback=false to get a link to login on your local machine.

由于这个 Stack 我是跑在 CVM 上,又懒得装桌面系统,所以在本地浏览器访问CVM,将 localhost 做调整。

https://CVM_IP:8885/oauth/authorize?client_id=cli&redirect_uri=code&response_type=code

我之前编译有问题,JS依赖没有编译进去,看日志返回了无效的css/js 文件,因此浏览器页面无法展示:

正常顺利的话,我们可以看到登录页面。

2 帐号注册

你可以使用管理员账号 admin,那就跳过这一节。

没有账号的话,需要先注册账号。这边TTN没处理好,WEB没有给与应该有的提示。

我注册时发现无法点击,看了调试日志才发现,原来无法注册“ttn”、“ttn_1”。

  INFO Finished unary call                      duration=268.898µs error=error:p
kg/identityserver/blacklist:blacklisted_id (the ID `ttn` can not be registered)
error_correlation_id=7d461d3db0f84c8f9a1004a3de4309fe error_name=blacklisted_id
error_namespace=pkg/identityserver/blacklist grpc_code=InvalidArgument grpc_meth
od=Create grpc_service=ttn.lorawan.v3.UserRegistry namespace=grpc request_id=01D
6F5D5NB0RC7J2AKT6HTQKY7
  INFO Finished unary call                      duration=76.578µs error=error:pk
g/ttnpb:identifiers (invalid identifiers) error_cause=invalid field UserID: valu
e 'ttn_1' must be a string conforming to regex "^[a-z0-9](?:[-]?[a-z0-9]){2,}$"
error_correlation_id=959871736a304a57b55737e52a89684d error_name=identifiers err
or_namespace=pkg/ttnpb grpc_code=InvalidArgument grpc_method=Create grpc_service
=ttn.lorawan.v3.UserRegistry namespace=grpc request_id=01D6F5DH4XJ5GVM87YQXRDV25
D

最终是使用 ttn-1 注册成功了。

grpc_service=ttn.lorawan.v3.UserRegistry namespace=db query=SELECT "id" FROM "co
ntact_info_validations"  WHERE (id = $1) request_id=01D6FEFM6EDV1N565BKNERG50Y r
ows=1 source=contact_info_store.go:171 values=[60c3ce12-7482-4661-abf2-e7c49c39a
c06]
  INFO Created email validation token           email=ttn@qq.com grpc_method=Cre
ate grpc_service=ttn.lorawan.v3.UserRegistry namespace=grpc request_id=01D6FEFM6
EDV1N565BKNERG50Y token=XIPV2CTVSG54D57MZDZ6HBFUVYWWQ7PQZSJQF26JP4KU7A5UBLDQ
  WARN Could not send email without email provider body=Please confirm your emai
l address for The Things Network Stack for LoRaWAN.

Your email address will be used as contact for user "ttn-1".

Reference: UDHB4FEG2UIBEQUFPG5BO5WMUEHOCLMEREOCLKQ
Confirmation Token: XIPV2CTVSG54D57MZDZ6HBFUVYWWQ7PQZSJQF26JP4KU7A5UBLDQ
 grpc_method=Create grpc_service=ttn.lorawan.v3.UserRegistry namespace=grpc requ
est_id=01D6FEFM6EDV1N565BKNERG50Y subject=Please confirm your email address for
The Things Network Stack for LoRaWAN to=ttn@qq.com
  INFO Finished unary call                      duration=207.139986ms grpc_metho
d=Create grpc_service=ttn.lorawan.v3.UserRegistry namespace=grpc request_id=01D6
FEFM6EDV1N565BKNERG50Y

3 账号登录,粘贴 authorization code

将页面返回的 authorization code 粘贴到命令行中。

./ttn-lw-cli login --callback=false
  INFO Opening your browser on https://localhost:8885/oauth/authorize?client_id=cli&redirect_uri=code&response_type=code
  WARN Could not open your browser, you'll have to go there yourself error=exec: "xdg-open": executable file not found in $PATH
  INFO After logging in and authorizing the CLI, we'll get an access token for future commands.
  INFO Please paste the authorization code and press enter
> 填入你的 OAUTH Code
INFO Got OAuth access token

END


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值