Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
Signed request methods improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
benorama committed Sep 14, 2010
1 parent ce91874 commit 5eb70d2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 53 deletions.
107 changes: 57 additions & 50 deletions src/facebook/sdk/FacebookApp.cfc
@@ -1,9 +1,8 @@
/**
* Copyright 2010 Affinitiz
* Title: FacebookApp.cfc
* Copyright 2010 Affinitiz, Inc.
* Author: Benoit Hediard (hediard@affinitiz.com)
* Date created: 01/08/10
* Last update date: 11/09/10
* Last update date: 09/09/10
* Version: V2.1.1 beta1
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand All @@ -26,43 +25,43 @@
component {

/**
* @description Facebook App URL
* @hint Ex.: http://apps.facebook.com/your-app
*/
property String appUrl;
/**
* @description Facebook App Id
* @hint
* @validate string
*/
property String appId;
/**
* @description Facebook application secret key
* @hint
* @validate string
*/
property String secretKey;
/**
* @description Canvas or Site URL
* @hint Ex.: http://youserver.com/yourapp
*/
property String siteUrl;
* @description Facebook App URL
* @hint Ex.: http://apps.facebook.com/your-app
*/
property String appUrl;
/**
* @description Facebook App Id
* @hint
* @validate string
*/
property String appId;
/**
* @description Facebook application secret key
* @hint
* @validate string
*/
property String secretKey;
/**
* @description Canvas or Site URL
* @hint Ex.: http://youserver.com/yourapp
*/
property String siteUrl;

variables.DROP_QUERY_PARAMS = "session,signed_request";
variables.VERSION = '2.1.1';
variables.DROP_QUERY_PARAMS = "session,signed_request";
variables.VERSION = '2.1.1';

/*
* @description Facebook App constructor
* @hint Requires an appId and its secretKey
*/
public FacebookApp function init(required String appId, required String secretKey, String appUrl = "", String siteUrl = "") {
setAppUrl(arguments.appUrl);
setAppId(arguments.appId);
setSecretKey(arguments.secretKey);
setSiteUrl(arguments.siteUrl);
//variables.accessTokenHttpService = new Http(url="https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=#variables.appId#&client_secret=#variables.secretKey#");
return this;
}
/*
* @description Facebook App constructor
* @hint Requires an appId and its secretKey
*/
public FacebookApp function init(required String appId, required String secretKey, String appUrl = "", String siteUrl = "") {
setAppUrl(arguments.appUrl);
setAppId(arguments.appId);
setSecretKey(arguments.secretKey);
setSiteUrl(arguments.siteUrl);
//variables.accessTokenHttpService = new Http(url="https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=#variables.appId#&client_secret=#variables.secretKey#");
return this;
}

/*
* @description Dump parameters for debug purpose.
Expand Down Expand Up @@ -179,17 +178,27 @@ component {
public Numeric function getProfileId() {
var parameters = structNew();
var profileId = 0;
if (structKeyExists(url, "signed_request")) {
parameters = parseSignedRequestParameters(url.signed_request);
} else if (structKeyExists(form, "signed_request")) {
parameters = parseSignedRequestParameters(form.signed_request);
}
parameters = parseSignedRequestParameters(getSignedRequest());
if (structKeyExists(parameters, "profile_id")) {
profileId = parameters.profile_id;
}
return profileId;
}

/*
* @description Get signed request
* @hint
*/
public String function getSignedRequest() {
var signedRequest = "";
if (structKeyExists(url, "signed_request")) {
signedRequest = url.signed_request;
} else if (structKeyExists(form, "signed_request")) {
signedRequest = form.signed_request;
}
return signedRequest;
}

/*
* @description Get user OAuth accessToken
* @hint
Expand Down Expand Up @@ -220,14 +229,12 @@ component {
* @description Get the session object.
* @hint This will automatically look for a signed session sent via the signed_request, Cookie or Query Parameters if needed.
*/
public Struct function getUserSession() {
public Struct function getUserSession(String signedRequest = "") {
var parameters = structNew();
var userSession = structNew();
// Try loading session from url.signed_request or form.signed_request
if (structKeyExists(url, "signed_request")) {
parameters = parseSignedRequestParameters(url.signed_request);
} else if (structKeyExists(form, "signed_request")) {
parameters = parseSignedRequestParameters(form.signed_request);
if (signedRequest == "") {
parameters = parseSignedRequestParameters(getSignedRequest());
}
if (structCount(parameters)) {
userSession = createSessionFromSignedRequestParameters(parameters);
Expand Down Expand Up @@ -399,7 +406,7 @@ component {
}
return parameters;
}

private Struct function parseSignedRequestParameters(required String signedRequest) {
var encodedParameters = listLast(trim(arguments.signedRequest), ".");
var encodedSignature = listFirst(trim(arguments.signedRequest), ".");
Expand All @@ -413,7 +420,7 @@ component {
}
return parameters;
}

private Boolean function validateUserSession(required Struct userSession) {
var valid = false;
if (isStruct(arguments.userSession)
Expand Down
6 changes: 3 additions & 3 deletions src/facebook/sdk/FacebookRestAPI.cfc
Expand Up @@ -4,7 +4,7 @@
* Author: Benoit Hediard (hediard@affinitiz.com)
* Date created: 01/08/10
* Last update date: 11/09/10
* Version: V2.1.1 beta1
* Version: V2.1.2 beta1
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
Expand Down Expand Up @@ -105,11 +105,11 @@ component {
return result['aid'];
}

public String function publishPhoto(required String profileId, required String aid, required String sourcePath, String message = "") {
public String function publishPhoto(required String profileId, required String albumId, required String sourcePath, String message = "") {
var result = structNew();
var httpService = new Http(url="https://api.facebook.com/method/photos.upload", method="POST");
httpService.addParam(type="url", name="access_token", value="#variables.ACCESS_TOKEN#");
httpService.addParam(type="formField", name="aid", value="#arguments.aid#");
httpService.addParam(type="formField", name="aid", value="#arguments.albumId#");
httpService.addParam(type="formField", name="uid", value="#arguments.profileId#");
httpService.addParam(type="file", name="data", file="#arguments.sourcePath#");
httpService.addParam(type="url", name="format", value="json");
Expand Down

0 comments on commit 5eb70d2

Please sign in to comment.