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 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题