使用Boxr gem Ruby SDK for Box API无法通过ID获取文件夹 [英] Unable to get folder by id using Boxr gem Ruby SDK for Box API

查看:111
本文介绍了使用Boxr gem Ruby SDK for Box API无法通过ID获取文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前在使用FormStack表单服务的Rails 5.2应用程序上工作. Formstack利用Box来存储服务.我开始使用 Boxr gem与Box API进行交互.

I'm currently working on a Rails 5.2 application where I'm using FormStack form service. Formstack makes use of Box for it's storing services. I started using Boxr gem to interact with the Box API.

要创建client,您将需要开发者令牌.

To create a client you will need a developer token.

client = Boxr::Client.new('{BOX_DEVELOPER_TOKEN}') 但是,此BOX_DEVELOPER_TOKEN每60分钟失效一次.因此,我决定使用JWT进行身份验证.

client = Boxr::Client.new('{BOX_DEVELOPER_TOKEN}') However, this BOX_DEVELOPER_TOKEN expires every 60 minutes. So I decided to use JWT for authentication.

因此,我通过以下方式生成token:

So I generate the token the following way:

token = Boxr::get_enterprise_token(private_key: ENV.fetch('JWT_PRIVATE_KEY'), private_key_password: ENV.fetch('JWT_PRIVATE_KEY_PASSWORD'), public_key_id: ENV.fetch('JWT_PUBLIC_KEY_ID'), enterprise_id: ENV.fetch('BOX_ENTERPRISE_ID'), client_id: ENV.fetch('BOX_CLIENT_ID'), client_secret: ENV.fetch('BOX_CLIENT_SECRET'))

这就是我随后用来生成客户端的内容:

This is what I then pass to generate the client:

client = Boxr::Client.new(token)

这将创建客户端:

#<Boxr::Client:0x000055fd60abb7e8
 @access_token={"access_token"=>"xxxxxxxxxxxxxxxx", "expires_in"=>3782, "restricted_to"=>[], "token_type"=>"bearer"},
 @as_user_id=nil,
 @client_id="xxxxxxxxxxxxxxx",
 @client_secret="xxxxxxxxxxxx",
 @enterprise_id="xxxxxxxxxxxxx",
 @identifier=nil,
 @jwt_private_key=
  "-----BEGIN ENCRYPTED PRIVATE KEY-----xxxxxxxxxxxxxx",
 @jwt_private_key_password="xxxxxxxxxxxxxxx",
 @jwt_public_key_id="xxxxxxxxxxxxxx",
 @refresh_token=nil,
 @token_refresh_listener=nil>

但是,当我尝试通过ID检索文件夹时,遇到了一个错误,我通过BOX_DEVELOPER_TOKEN创建客户端时并没有得到这个错误.

However, when I try to retrieve a folder by the ID I get an error which I didn't get when I passed the BOX_DEVELOPER_TOKEN to create the client.

folder = client.folder_from_id("12345678")

Boxr::BoxrError: 404: Not Found
from /usr/local/bundle/gems/boxr-1.4.0/lib/boxr/client.rb:239:in `check_response_status'

在企业设置中,我通过提供API TOKEN来访问该应用程序.我不确定为什么无法获得该文件夹.当我转到文件夹ID时,该文件夹在那里,并且在开发人员控制台中,我具有管理员访问权限.有帮助吗?

In enterprise settings I gave access to the application by providing the API TOKEN. I'm not sure why I can not get the folder. When I go to the folder ID, the folder is there and in the developer console, I have admin access. Any help?

推荐答案

您看到的行为是由于您的开发人员令牌将调用者身份验证为您自己的个人用户帐户,但是在使用JWT身份验证时,API会进行调用是作为代表应用程序本身的特殊服务帐户创建的.这些帐户默认情况下无权访问相同的内容;您希望在它们之间共享的任何文件夹都必须进行明确协作,或者必须允许服务帐户模拟拥有该文件夹的用户帐户.您可以在 https://developer.box.com/上了解有关此主题的更多信息. v2.0/docs/service-account

The behavior you're seeing is due to the fact that your Developer Token authenticates the caller as your own personal user account, but when using JWT Authentication the API calls are made as a special Service Account which represents the application itself. These accounts do not by default have access to the same content; any folders you wish to share between them must either be explicitly collaborated, or the Service Account must be permitted to impersonate the user account that owns the folder. You can read more about this topic at https://developer.box.com/v2.0/docs/service-account

这篇关于使用Boxr gem Ruby SDK for Box API无法通过ID获取文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆