简体   繁体   English

验证外部应用到Salesforce实例

[英]Authenticate External App to Salesforce instance

I am building a mobile application that will need to fetch data from my salesforce instance. 我正在构建一个移动应用程序,它将需要从我的salesforce实例中获取数据。 I have no problem with SOQL to grab the appropriate data. 我对SOQL没问题,可以获取适当的数据。 However, I do not want the user of the mobile app to have to log in to get a token, which I need to use to access the data. 但是,我不希望移动应用程序的用户必须登录以获得令牌,我需要使用令牌来访问数据。

Is it possible to authenticate the app via appId and client secret in the application to allow the appropriate use/access of the APIs? 是否可以通过应用程序中的appId和客户端机密对应用程序进行身份验证,以允许正确使用/访问API? This would be similar to authenticating an app to a Parse or Firebase instance without requiring an authenticated user. 这类似于在不需要经过身份验证的用户的情况下将应用程序验证为Parse或Firebase实例。

Thanks! 谢谢!

This is an example in nodejs/Express , in this example i get the accounts: 这是nodejs / Express中的示例,在此示例中,我获得了帐户:

var express = require('express');
var router = express.Router();
var nforce = require('nforce');
/* GET home page. */
router.get('/', function(req, res, next) {

var accounts =[];
// create the connection with the Salesforce connected app
var org = nforce.createConnection({
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
redirectUri: process.env.CALLBACK_URL,
mode: 'single'
});

 // authenticate and return OAuth token
 org.authenticate({
 username: process.env.USERNAME,
 password: process.env.PASSWORD+process.env.SECURITY_TOKEN
 }, function(err, resp){
  if (!err) {

  console.log('Successfully logged in! Cached Token: ' + 
  org.oauth.access_token);
  // execute the query
  org.query({ query: 'select id, name from account' }, function(err, resp){
    if(!err && resp.records) {
      // output the account names
      for (i=0; i<resp.records.length;i++) {
        //console.log(resp.records[i].get('name'));
        accounts.push(resp.records[i].get('name'));
      }

      res.render('index', { title:'Accounts',accounts:accounts });
    }
  });
}
 if (err) console.log(err);
 }); 

 //console.log(accounts);

 });

 module.exports = router;

You need to get you api crendentials for authenticate , it does not matter what language are you using the concept is the same. 您需要获取用于身份验证的api凭据,无论使用哪种语言,概念都一样。

USERNAME : Your Salesforce User name USERNAME:您的Salesforce用户名

PASSWORD: Your Salesforce Password 密码:您的Salesforce密码

SECURITY_TOKEN: Your user security token , if you don't have it you can go to My Settings -Personal -Reset my security token and Salesforce will send you the token to your email. SECURITY_TOKEN:您的用户安全令牌,如果没有,可以转到我的设置-个人-重置我的安全令牌,Salesforce会将令牌发送给您的电子邮件。

The other parameters are parameters you get from your app , so you have to register the app to get the security tokens. 其他参数是您从应用程序获取的参数,因此您必须注册该应用程序才能获取安全令牌。

For create a connected apd You go to : Setup -Build-Create Apps in the section of Connected Apps create a new one. 要创建连接的apd,请转到:“连接的应用程序”部分中的“设置-建立-创建应用程序”以创建一个新的应用程序。 the connected api generate a consumer key and a Consumer secret. 连接的api会生成使用者密钥和使用者密钥。

CLIENT_ID: Is the consumer key CLIENT_ID:是使用者密钥

CLIENT_SECRET:Is the Consumer secret CLIENT_SECRET:这是消费者的秘密吗

CALLBACK_URL: The callback url in my example is : http://localhost:3000 CALLBACK_URL:在我的示例中,回调URL为: http:// localhost:3000

This is not natively possible. 这在本地是不可能的。 All access to data/meta data in salesforce goes through a salesforce user account. Salesforce中对数据/元数据的所有访问都通过Salesforce用户帐户进行。 User accounts auth via username/pass, or via SSO (oAuth/SAML), or "Delegated Auth" (a pre-SAML auth service). 通过用户名/密码或SSO(oAuth / SAML)或“委派的身份验证”(SAML之前的身份验证服务)进行用户帐户身份验证。

Creating a "Connected App" is a feature, enabled by the salesforce admin, which enables your mobile app to connect via oAuth, along with a public/private key pair. 创建“连接的应用程序”是由salesforce管理员启用的功能,该功能使您的移动应用程序可以通过oAuth以及公共/私有密钥对进行连接。 However, Login is still required. 但是,仍然需要登录。

Perhaps you could place middleware between salesforce and your API - the middleware would connect to salesforce using a salesforce user account, while the API that it exposes accepts your public/private key. 也许您可以在Salesforce和您的API之间放置中间件-中间件将使用salesforce用户帐户连接到salesforce,而其公开的API则接受您的公钥/私钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM