Object
callWebService
(
service
)
openmail.Application.callWebService, but will add any authorization information needed to make the call.
...
<script>
var statusURL = "http://social.yahooapis.com/v1/user/{guid}/presence/presence";
var oauth = openmail.Application.getAuthService({profile:'oauth'});
function loadStatus() {
oauth.callWebService(
{
url: statusURL.replace('{guid}',guid),
method: "GET",
parameters: {format: 'json'}
},
function (response) {
alert(response.data);
});
}
</script>
...
<button onclick='loadStatus()'>load status</button>
...
service
< Object >
service may include the following:
url: String Target URL
method: String "GET" or "POST"
parameters: Object A map of key/value pairs to use as the query string or the POST body
handler: function A callback function
Object
Object contains the HTTP body returned by the Web service. Object contains an error message describing the failure.
Object
getStatus
(
handler
)
getStatus() is used to decide whether logging in is required.
<script>
...
var oauth = openmail.Application.getAuthService({profile:'oauth'});
oauth.getStatus( function(args) {
if (args.error) {
// handle error
}
if (args.data.status == 'ok') {
// ready to make calls
} else if (args.data.status == 'authorization required') {
// kick off authorization flow
}
...
</script>
handler
< function >
A callback function
Object
status : One of following: 'ok', 'failed', or 'authorization required'. info : If status is 'ok', depending on the profile type, data holds some additional information.
Object
getUserAuthorizationURL
(
params
,
handler
)
getUserAuthorizationURL() is used to 'redirect' the user.
<script>
...
// handleSignIn needs to provide a way for the user to signal that she has completed
// authorization on the 3rd party site.
function handleSignIn() {...}
...
var oauth = openmail.Application.getAuthService({profile:'oauth'});
oauth.getStatus( function(args) {
if (args.error) {//handle error}
if (args.data.status == 'ok') {
// ready to make calls
} else if (args.data.status == 'authorization required') {
oauth.getUserAuthorizationURL({request:{},authorization:{permissions:'write'}},
function(response) {
if (response.error) {...} //handle errror
YAHOO.util.Dom.get("oauth_signin").href = response.data.url;
YAHOO.util.Event.addListener("oauth_signin", "click", handleSignIn);
});
}
...
</script>
...
<a href="javascript:void(0);" id="oauth_signin" target="_blank">Authorize!</a>
params
< Object >
An object containing the configuration of the auth service requested. The object has the following members:request: The properties of the request object will be added to the call for the request tokenauthorization: The properties of the request object will be added to the authorization urlhandler
< function >
A callback function
Object
url : The authorization URL.
Object
notifyAuthorizationReceived
(
handler
)
notifyAuthorizationReceived() is used to continue the authorization flow.
<script>
...
var oauth = openmail.Application.getAuthService({profile:'oauth'});
...
function completeAuth() {
oauth.notifyAuthorizationReceived(function (response) {
if (response.error) {
// handle error
} else {
// handle completion.
//response.data.info contains additional data from the service
}
});
...
</script>
<button onclick='completeAuth()'>Authorization Complete!</button>
handler
< function >
A callback function
Object
info : Additional information is returned by the service.
Object
removeAuthorization
(
handler
)
removeAuthorization() is used to log out.
<script>
...
var oauth = openmail.Application.getAuthService({profile:'oauth'});
...
function logout() {
oauth.removeAuthorization(function (response) {
if (response.error) {//handle error}
});
...
</script>
<button onclick='logout()'>Log out!</button>
handler
< function >
A callback function
Object