duanlan2003 2014-12-19 16:33
浏览 63
已采纳

在Magento中存储第三方服务凭据的“正确”位置在哪里?

I’m implementing a Magento Extension which connects to a third-party API. I’m brand-new to Magento, but familiar with MVC systems in general.

My question is simply, "Where (and how?) should I store the credentials used to access this third-party API? I could create a database table and store them there, but it feels like overkill. I’ve seen people mention using the Magento cache as a key/value store, but it sounds too fragile. I’ve noticed that Magento seems to have some sort of config object (not really dug into it yet), maybe that’s my best option?

Which of these (if any) is ‘correct’? Which will cause me the fewest headaches in the long run?

it goes without saying that i will need to salt/hash these credentials, but i guess the same question applies to ‘where should i store the salt’?

  • 写回答

1条回答 默认 最新

  • dongxu4023 2014-12-20 20:18
    关注

    The typical Magento practice for something like this would be to store them in the database. You can define the database fields and user interface to maintain these credentials through the code in your extension.

    A perfect example of this in the core codebase would be the shipping carrier modules. Take a look at app/code/core/Mage/Usa/etc/config.xml:

    ...
    <fedex>
        <account backend_model="adminhtml/system_config_backend_encrypted"/>
        <meter_number backend_model="adminhtml/system_config_backend_encrypted"/>
        <key backend_model="adminhtml/system_config_backend_encrypted"/>
        <password backend_model="adminhtml/system_config_backend_encrypted"/>
        ...
    </fedex>
    ...
    

    By storing the credentials this way, these fields will be available in the administrative section of Magento where a business user can enter or update the credentials and they will be stored as encrypted values in the database. You can access them in your code using Mage::getStoreConfig('carriers/fedex/account'). Hopefully this gets you pointed in the right direction.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看