Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add return_ssl_resources option to facebook module #265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ everyauth.facebook
.callbackPath('/auth/facebook/callback')
.scope('email') // Defaults to undefined
.fields('id,name,email,picture') // Controls the returned fields. Defaults to undefined
.returnSSLResources(true) // Return url resources with https prefix. Defaults to undefined (false)
```

If you want to see what the current value of a
Expand All @@ -385,6 +386,7 @@ configured parameter is, you can do so via:
```javascript
everyauth.facebook.scope(); // undefined
everyauth.facebook.fields(); // undefined
everyauth.facebook.returnSSLResources(); // undefined
everyauth.facebook.entryPath(); // '/auth/facebook'
```

Expand Down
14 changes: 9 additions & 5 deletions lib/modules/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var fb = module.exports =
oauthModule.submodule('facebook')
.configurable({
scope: 'specify types of access: See http://developers.facebook.com/docs/authentication/permissions/',
fields: 'specify returned fields: See http:/developers.facebook.com/docs/reference/api/user/'
fields: 'specify returned fields: See http:/developers.facebook.com/docs/reference/api/user/',
returnSSLResources: 'indicates whether to return url resources with https prefix (to avoid mixed content warning in https sites)'
})

.apiHost('https://graph.facebook.com')
Expand Down Expand Up @@ -39,11 +40,14 @@ oauthModule.submodule('facebook')

.fetchOAuthUser( function (accessToken) {
var p = this.Promise();
var fieldsQuery = "";
if (this._fields && this._fields.length > 0){
fieldsQuery = "?fields=" + this.fields();
var query = {};
if (this.fields() && this.fields().length > 0){
query.fields = this.fields();
}
this.oauth.get(this.apiHost() + '/me' + fieldsQuery, accessToken, function (err, data) {
if (this.returnSSLResources()){
query.return_ssl_resources = this.returnSSLResources();
}
this.oauth.get(this.apiHost() + '/me' + url.format({ query: query }), accessToken, function (err, data) {
if (err) return p.fail(err);
var oauthUser = JSON.parse(data);
p.fulfill(oauthUser);
Expand Down