This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class OAuthCallbackController { | |
public OAuthModel oauthModel {get; set;} | |
public String resBody {get; set;} | |
public List<Account> accounts {get; set;} | |
public OAuthCallbackController(){ | |
String error = ApexPages.currentPage().getParameters().get('error'); | |
String errorDescription = ApexPages.currentPage().getParameters().get('error_description'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page showHeader="false" sidebar="false" controller="OAuthCallbackController"> | |
<apex:pageBlock title="SalesforceだけでOAuthを試してみる"> | |
<apex:pageMessages /> | |
<apex:outputLabel value="Result:" /> | |
<br/> | |
<textarea rows="10" cols="100">{!resBody}</textarea> | |
</apex:pageBlock> | |
<apex:form id="fm"> | |
<apex:outputPanel rendered="{!NOT(ISNULL(resBody))}"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class OAuthInitiateController { | |
public static final String CLIENT_ID = <CLIENT_ID>; | |
public static final String CLIENT_SECRET = <CLIENT_SECRET>; | |
public static final String CALLBACK_URL = 'https://xxxx/apex/OAuthCallback'; | |
public PageReference initiate(){ | |
String authorizeUrl = 'https://login.salesforce.com/services/oauth2/authorize'; | |
authorizeUrl += '?response_type=code'; | |
authorizeUrl += '&client_id=' + CLIENT_ID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page showHeader="false" sidebar="false" controller="OAuthInitiateController"> | |
<apex:form > | |
<apex:pageBlock title="SalesforceだけでOAuthを試してみる"> | |
<apex:commandButton action="{!initiate}" value="OAuth認証フロー開始" /> | |
</apex:pageBlock> | |
</apex:form> | |
</apex:page> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onLoadFinished(Loader<PartnerConnection> loader, PartnerConnection connection) { | |
this.connection = connection; | |
if(connection == null){ | |
Toast.makeText(this, "ログインに失敗しました。", Toast.LENGTH_SHORT).show(); | |
}else{ | |
Toast.makeText(this, "ログインに成功しました。", Toast.LENGTH_SHORT).show(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public PartnerConnection loadInBackground() { | |
PartnerConnection connection = null; | |
ConnectorConfig config = new ConnectorConfig(); | |
config.setUsername(username); | |
config.setPassword(password); | |
try { | |
// PartnerConnectionのインスタンス生成時にログインが実行される |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onClick(View v) { | |
// ユーザIDの取得 | |
EditText etUsername = (EditText)findViewById(R.id.et_username); | |
String username = etUsername.getText().toString(); | |
// パスワードの取得 | |
EditText etPassword = (EditText)findViewById(R.id.et_password); | |
String password = etPassword.getText().toString(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CompactLayoutVo compactLayoutVo = new CompactLayoutVo(root); | |
Intent intent = new Intent(DescribeGlobalActivity.this, SearchActivity.class); | |
intent.putExtra(SearchActivity.ARG_COMPACT_LAYOUT_VO, compactLayoutVo); | |
intent.putExtra(SearchActivity.ARG_NAME, name); | |
intent.putExtra(SearchActivity.ARG_LABEL, label); | |
startActivityForResult(intent, Const.REQUEST_CODE_DESCRIBE_GLOBAL_ACTIVITY); |
NewerOlder