首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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

前言

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

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

1 获取 OAUTH 链接

代码语言:javascript
复制
# ./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 做调整。

代码语言:javascript
复制
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”。

代码语言:javascript
复制
  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
代码语言:javascript
复制
  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 注册成功了。

代码语言:javascript
复制
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 粘贴到命令行中。

代码语言:javascript
复制
./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

下一篇
举报
领券