I am trying to add an account to QuickBooks Online using Intuit IPP:
https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0200_DevKits_for_Intuit_Partner_Platform/0100_IPP_.NET_DevKit/Query_Filters/QuickBooks_Online
How do I get the access token and the access token secret? Here is my code:
class Program
{
static string appToken = "xxx";
static string oAuthConsumerKey = "xxx";
static string oAuthConsumerSecret = "xxx";
static void Main(string[] args)
{
OAuthRequestValidator oauthValidator = new OAuthRequestValidator(appToken, "", oAuthConsumerKey, oAuthConsumerSecret);
ServiceContext context = new ServiceContext(oauthValidator, appToken, "1234", IntuitServicesType.QBD);
DataServices dataServices = new DataServices(context);
Account account = new Account();
account.Desc = "TEST PLEASE DELETE";
string guid = Guid.NewGuid().ToString("N");
guid = guid.Substring(0, 30);
account.Name = guid;
account.Type = Intuit.Ipp.Data.Qbd.AccountTypeEnum.Liability;
account.TypeSpecified = true;
account.Subtype = "Accounts Payable";
Account resultAccount = dataServices.Add(account) as Account;
}
}
I figured it out. Look at step 6 here:
http://ippblog.intuit.com/blog/2012/09/ode-to-oauth-and-rest-apis-and-how-i-love-thee-not.html
Joseph,
For Future reference and for others the documentation for your question is located here:
IPP Oauth Documentation
regards,
Jarred
Related
I make video chatting use agora
https://docs.agora.io/en/video-calling/develop/integrate-token-generation?platform=unity
I made it by following the guide above.
Play UnityEditor and Create a token with a token generator and start join channel.
But Channel Join is fail and I receive "Error code:109 msg:channel key expired"
It's a new token make by token generator, but I don't know why it's being expired.
sombody help me. thx.
private string appId = "my_agora_consone_appId";
private string appCertificate = "my_agora_consone_appCertificate ";
private string channelName = "vdch57";
private string uid = UserInfo.Instance.userKey.ToString();
private string userAccount = "User account";
private int expirationTimeInSeconds = 3600;
public string MakeToken(string channelName)
{
AccessToken token = new AccessToken(appId, appCertificate, channelName, uid);
string token2 = SignalingToken.getToken(appId, appCertificate, userAccount, expirationTimeInSeconds);
token.addPrivilege(Privileges.kJoinChannel, Convert.ToUInt32(expirationTimeInSeconds));
string result = token.build();
return result;
}
This is the code i used for capture payments in Paypal
OAuthTokenCredential tokenCredential = new OAuthTokenCredential("<CLIENT_ID>", "<CLIENT_SECRET>");
var accessToken = tokenCredential.GetAccessToken();
Authorization authorization = Authorization.Get(accessToken, "5RA45624N3531924N");
Capture capture = new Capture();
Amount captureAmount = new Amount();
captureAmount.currency = "USD";
captureAmount.total = "1";
capture.amount = captureAmount;
capture.is_final_capture = true;
Capture responseCapture = authorization.Capture(accessToken, capture);
But it says
Argument type 'string' is not assignable to parameter type 'PayPal.Api.APIContext'
in following line accessToken parameter
Authorization authorization = Authorization.Get(accessToken, "5RA45624N3531924N");
How can i solve this issue?
Create a new class 'Configuration.cs'.
public static class Configuration
{
public readonly static string ClientId;
public readonly static string ClientSecret;
static Configuration()
{
var config = GetConfig();
ClientId = config["clientId"];
ClientSecret = config["clientSecret"];
}
public static Dictionary<string,string> GetConfig()
{
return PayPal.Api.ConfigManager.Instance.GetProperties();
}
private static string GetAccessToken()
{
var config = GetConfig();
OAuthTokenCredential credential = new OAuthTokenCredential(ClientId, ClientSecret, config);
string accessToken = credential.GetAccessToken();
return accessToken;
}
public static APIContext GetAPIContext()
{
string accessToken = GetAccessToken();
APIContext apiContext = new APIContext(accessToken);
apiContext.Config = GetConfig();
return apiContext;
}
}
GetAPIContext method will return APIContext object. Pass that object as a parameter to Authorization.Get method instead of "accessToken".
APIContext apiContext = Configuration.GetAPIContext();
Authorization authorization = Authorization.Get(apiContext, "6SY29185GS4409204");//Provide Payment Id returned after authorizing payment.
You specified the token in the first parameter, it's not correct.
According to below definition:
public static Authorization Get(APIContext apiContext, string authorizationId)
You should specify APIContext type.
Can you try the code like below:
var apiContext = Configuration.GetAPIContext();
var authorization = Authorization.Get(apiContext, authorizationId);
I'm building a windows phone 8.1 app that allow user to login facebook account.
There is my code:
string productId = "myproductid";
string facebookAppId = "myfacebookappid";
string redirectUri = "msft-"+productId+"://authorize";
string scope = "public_profile,email"; // What you want to fetch from the facebook user
string responseType = "token"; // Other response types possible
UriBuilder authUri = new UriBuilder("https://www.facebook.com/dialog/oauth");
authUri.Query = "client_id=" + facebookAppId + "&redirect_uri=" + redirectUri + "&scope=" + scope + "&response_type=" + responseType;
var success = await Windows.System.Launcher.LaunchUriAsync(uriToLaunch);
And code in App.xaml.cs:
protected override void OnActivated(IActivatedEventArgs args)
{
base.OnActivated(args);
if (args.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
{
App.MobileService.LoginComplete(args as WebAuthenticationBrokerContinuationEventArgs);
}
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
WwwFormUrlDecoder decoder = new WwwFormUrlDecoder(eventArgs.Uri.Fragment);
string fbAccessToken = decoder.GetFirstValueByName("#access_token");
/* Now you can use the access token to interact with the Facebook API */
}
}
But how to get user's email and profile from "fbAccessToken"?
Thanks.
You can use the graph APIs of facebook
graph.facebook.com/me?access_token={0}
Please refer this link - https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3
Add scope/Extended Permission to get user profile etc.,
string scope ="user_about_me,read_stream,publish_actions,user_birthday,offline_access,email"
i am creating an application in asp.net, which will use the user's facebook data using its api's,
but in order to access the Fb api's we need to perform the OAuth(2.0) first.
i did that too by using the DotNetOpenAuth library in the following code:
private static readonly FacebookClient client = new FacebookClient
{
ClientIdentifier = ConfigurationManager.AppSettings["fbAppID"],
ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(ConfigurationManager.AppSettings["fbSecret"]),
};
protected void Page_Load(object sender, EventArgs e)
{
IAuthorizationState authorization = client.ProcessUserAuthorization();
if (authorization == null)
{
// Kick off authorization request
client.RequestUserAuthorization();
}
else
{
var req = WebRequest.Create("https://graph.facebook.com/oauth/access_token?client_id=" + ConfigurationManager.AppSettings["facebookAppID"] + "&client_secret=" + ConfigurationManager.AppSettings["facebookAppSecret"] + "&grant_type=fb_exchange_token&fb_exchange_token=" + Uri.EscapeDataString(authorization.AccessToken));
var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
var graph = FacebookGraph.Deserialize(responseStream);
this.nameLabel.Text = HttpUtility.HtmlEncode(graph.Name);
}
}
}
}
my question here is, how can i get the long-lived access token of facebook using the DotNetOpenAuth library, so that user do not need to login again and again and i can store that somewhere.
please help me.
If possible use Facebook SDK for .Net to create access token for long time. may be 60 days.
using Facebook;
var cl = new FacebookClient(short_lived_access_token);
dynamic result = client.Post("oauth/access_token", new
{
client_id = "your app id",
client_secret = "your app secret",
grant_type = "fb_exchange_token",
fb_exchange_token = client.AccessToken
});
var long_lived_access_token = result.access_token;
I am stucked in authenticating my application running on Shiro with Facebook OAuth. I really don't know what am I doing wrong. Bascially, my problem is when I get a "code" from Facebook. I want shiro to authenticate it using that code.
This is my authentication code.
FacebookToken token = null;
try{
org.apache.shiro.subject.Subject currentUser = SecurityUtils.getSubject();
//currentUser.logout();
//This is done to avoid temporary multiple url hit.., when the user is not logged out
token = new FacebookToken(code);
currentUser.login(token); //returns true if valid
result = true;
}catch (UnknownAccountException uae) {
log.info("There is no user with username of " + token.getPrincipal());
} catch (IncorrectCredentialsException ice) {
log.info("Password for account " + token.getPrincipal() + " was incorrect!");
} catch (LockedAccountException lae) {
log.info("The account for username " + token.getPrincipal() + " is locked. " +
"Please contact your administrator to unlock it.");
}
// ... catch more exceptions here (maybe custom ones specific to your application?
catch (AuthenticationException ae) {
log.info("Authentication exception Here.");
}
Here is my facebook token class:
public class FacebookToken implements AuthenticationToken {
private static final long serialVersionUID = 1L;
private String code;
public FacebookToken(){
}
public FacebookToken(String code){
this.code = code;
}
public Object getCredentials() {
return null; //Credentials are handled by facebook
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Object getPrincipal() {
return null; //Not known facebook does the login
}
I have the realm for facebook that is extending authorization realms.
public class FacebookRealm extends AuthorizingRealm {
}
and finally here is my shiro.ini file:
[main]
#authc.loginUrl = /login
#authc.successUrl = /hello
#logout.redirectUrl = /hello
# ------------------------
# Database
# Own Realm
jdbcRealm = com.shiro.common.controller.MyCustomRealm
facebookRealm = com.facebook.login.FacebookRealm
# Sha256
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
# base64 encoding, not hex in this example:
sha256Matcher.storedCredentialsHexEncoded = false
sha256Matcher.hashIterations = 1024
#Facebook Credential matcher
fbCredentialsMatcher = com.facebook.login.FacebookCredentialsMatcher
jdbcRealm.credentialsMatcher = $sha256Matcher
facebookRealm.credentialsMatcher = $fbCredentialsMatcher
# User Query
# default is "select password from users where username = ?"
jdbcRealm.authenticationQuery = SELECT password, salt FROM User WHERE email = ?
# permissions
jdbcRealm.permissionsLookupEnabled = true
jdbcRealm.userRolesQuery = select roleName from UserRole where email = ?
jdbcRealm.permissionsQuery = select permission from RolesPermission where roleName = ?
# Connection
ds = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
ds.serverName = localhost
ds.user = root
ds.password = root123
ds.databaseName = testdb
jdbcRealm.dataSource=$ds
#authc.usernameParam = email
#authc.passwordParam = password
#authc.failureKeyAttribute = shiroLoginFailure
# Use Built-in Chache Manager
builtInCacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $builtInCacheManager
#securityManager.realms = $facebookRealm,$jdbcRealm
securityManager.realms = $facebookRealm
# -----------------------------------------------------------------------------
[urls]
#/hello = authc
#/login = authc
#/admin.jsp = authc, perms["admin:access"]
Now when do i debug and reach at currentuser.login methods and go inside, it throws an exception saying
Realm [FacebookRealm#52039826] does not support authentication token [FacebookToken#132d9844]. Please ensure that the appropriate Realm implementation is configured correctly or that the realm accepts AuthenticationTokens of this type.
Please suggest me whether am I doing correct, or not !! Am i missing any configuration or any thing else. Thank you !!
You should extend your FacebookRealm with the following method:
#Override
public boolean supports(AuthenticationToken token) {
return token instanceof FacebookToken;
}
or add the following line to your ini:
facebookRealm.authenticationTokenClass=<realpackage>.FacebookToken