Dropbox Authentication In Salesforce - Easy Setup (Authentication Part 1)
来源:互联网 发布:淘宝新店访客多少正常 编辑:程序博客网 时间:2024/05/18 06:23
From log time managing data is a big deal, and a lot are concerned with it. Multiple options are available to handle this, out of them Dropbox, Box.com, Amazon are the main ones.
In this blog Authentication with Dropbox is explained so developers can get started.
Step 1 : Create an account on Dropbox, then go to this link and create an app. It will create "App Key" and "App Secret" which we will be using in Salesforce. Leave the OAuth2 section blank for now.
Step 2 : Go to salesforce and create this apex class (DropboxController) :
Step 3 : Now create visualforce page (DropboxPage) :
Step 4 : Replace the code with your values
1 . As you can see we have this in code :
You have to replace "client_id" with your "App Key" (redirect_uri is the complete page URL which we've just created). Now as visualforce page is created you can fill the OAuth2 section as shown in the screenshot above in dropbox.
2. Replace "dpmmll522bep6pt" in this line
with you "App Secret"
Step 5 : Don't forget to set the remote site settings for dropbox
Now all set to go. Open the page "https:// ..... /apex/DropboxPage" and hit "Dropbox Authentication". In the debug you will get the access token which you can further use to hit Dropbox APIs.
Please note, code is not beautified as this is just to explain how you can authenticate dropbox with salesforce. A lot more creativity can be applied here.
From here everything is set and you are ready to hit the dropbox API and fetch the data or store the data. Complete documentation is here.
In this blog Authentication with Dropbox is explained so developers can get started.
Step 1 : Create an account on Dropbox, then go to this link and create an app. It will create "App Key" and "App Secret" which we will be using in Salesforce. Leave the OAuth2 section blank for now.
Step 2 : Go to salesforce and create this apex class (DropboxController) :
- public class DropboxController
- {
- //Fetched from URL
- String code ;
- public DropboxController()
- {
- code = ApexPages.currentPage().getParameters().get('code') ;
- //Get the access token once we have code
- if(code != '' && code != null)
- {
- AccessToken() ;
- }
- }
- public PageReference DropAuth()
- {
- //Authenticating
- PageReference pg = new PageReference('https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=vaabb5qz4jv28t5&redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage&state=Mytesting') ;
- return pg ;
- }
- public void AccessToken()
- {
- //Getting access token from dropbox
- String tokenuri = 'https://api.dropbox.com/1/oauth2/token?grant_type=authorization_code&code='+code+'&redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage';
- HttpRequest req = new HttpRequest();
- req.setEndpoint(tokenuri);
- req.setMethod('POST');
- req.setTimeout(60*1000);
- Blob headerValue = Blob.valueOf('vaabb5qz4jv28t5' + ':' + 'dpmmll522bep6pt');
- String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
- req.setHeader('Authorization', authorizationHeader);
- Http h = new Http();
- String resp;
- HttpResponse res = h.send(req);
- resp = res.getBody();
- System.debug(' You can parse the response to get the access token ::: ' + resp);
- }
- }
Step 3 : Now create visualforce page (DropboxPage) :
- <apex:page controller="DropboxController">
- <apex:form>
- <apex:pageblock>
- <apex:commandbutton action="{!DropAuth}" value="Dropbox Authentication">
- </apex:commandbutton></apex:pageblock>
- </apex:form>
- </apex:page>
Step 4 : Replace the code with your values
1 . As you can see we have this in code :
- PageReference pg = new PageReference('https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=vaabb5qz4jv28t5&redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage&state=Mytesting') ;
You have to replace "client_id" with your "App Key" (redirect_uri is the complete page URL which we've just created). Now as visualforce page is created you can fill the OAuth2 section as shown in the screenshot above in dropbox.
2. Replace "dpmmll522bep6pt" in this line
- Blob headerValue = Blob.valueOf('vaabb5qz4jv28t5' + ':' + 'dpmmll522bep6pt');
Step 5 : Don't forget to set the remote site settings for dropbox
Now all set to go. Open the page "https:// ..... /apex/DropboxPage" and hit "Dropbox Authentication". In the debug you will get the access token which you can further use to hit Dropbox APIs.
Please note, code is not beautified as this is just to explain how you can authenticate dropbox with salesforce. A lot more creativity can be applied here.
From here everything is set and you are ready to hit the dropbox API and fetch the data or store the data. Complete documentation is here.
0 0
- Dropbox Authentication In Salesforce - Easy Setup (Authentication Part 1)
- HOWTO Setup LDAP GSSAPI+Kerberos Authentication in CAS
- How to setup Git http authentication using LDAP in Apache
- Authentication
- Authentication in IIS
- Customizing authentication in Django
- User Authentication in Django
- HOWTO Setup Dual Authentication in CAS - SSL Client Auth and LDAP
- Authorization and Authentication In Hadoop
- Google+ Authentication in ASP.Net
- Weaknesses in MS-CHAPv2 authentication
- HTTP Basic Authentication in JMeter
- Custom Authentication Provider in Spring
- Cookie-based Authentication in AngularJS
- SQL Server 2000 Security - Part 2 (Authentication)
- Setup the SSH server to use keys for authentication
- bypass dll authentication in sygate and such
- Explained: Forms Authentication in ASP.NET 2.0
- android studio 升级到1.0出现的几个问题
- Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱
- Cocos Code IDE执行效率太慢,Sublime+QuickXDev依然是最佳的cocos2d-x + Lua编辑器
- Android 读取R.raw文件夹下图片的分辨率问题
- Go语言-闭包
- Dropbox Authentication In Salesforce - Easy Setup (Authentication Part 1)
- Android Service完全解析,关于服务你所需知道的一切(上)
- 参数化查询 需要参数 但未提供该参数。
- Cocos2d-x下Lua调用自定义C++类和函数的最佳实践
- Core Data
- iOS下拉刷新
- iOS7最佳实践:一个天气App案例
- Android Service完全解析,关于服务你所需知道的一切(下)
- Java_MD5加密