I have implemented a new module for hello.js.
I need the auth
, grant
and base
to be dynamic.
Is there a way to set/override these values from the hello.init()
call?
My module looks like this:
(function(hello) {
hello.init({
my_service_name: {
name: 'My-Service-Name',
oauth: {
version: 2,
auth: 'http://mydomain/oauth/authorize',
grant: 'http://mydomain/oauth/token'
},
scope: {
basic: ['basic_scope']
},
base: 'http://mydomain/',
xhr: function(p) {
if (p.method !== 'get' && p.data) {
// Serialize payload as JSON
p.headers = p.headers || {};
p.headers['Content-Type'] = 'application/json';
if (typeof (p.data) === 'object') {
p.data = JSON.stringify(p.data);
}
}
return true;
}
}
});
})(hello);
and my hello.init()
call:
hello.init({
my_service_name: server.consumerKey
}, {
redirect_uri : server.callbackUrl,
});
The use-case is that the application I am developing will communicate with several servers, so I cannot hardcode the URLs in the module's file.
I figured out that I can override the default settings by passing the whole
oauth
object in thehello.init()
call: