foam-framework
Version:
MVC metaprogramming framework
55 lines (48 loc) • 1.7 kB
JavaScript
/**
* @license
* Copyright 2015 Google Inc. All Rights Reserved.
*
* 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 a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
CLASS({
name: 'OAuth2WebClient',
package: 'foam.oauth2',
help: 'Strategy for OAuth2 when running as a web page.',
extends: 'foam.oauth2.OAuth2',
methods: {
refreshNow_: function(ret, opt_forceInteractive) {
var self = this;
var w;
var cb = wrapJsonpCallback(function(code) {
self.accessToken = code;
try {
ret(code);
} finally {
w && w.close();
}
}, true /* nonce */);
var path = location.pathname;
var returnPath = location.origin +
location.pathname.substring(0, location.pathname.lastIndexOf('/')) + '/oauth2callback.html';
var queryparams = [
'?response_type=token',
'client_id=' + encodeURIComponent(this.clientId),
'redirect_uri=' + encodeURIComponent(returnPath),
'scope=' + encodeURIComponent(this.scopes.join(' ')),
'state=' + cb.id,
'approval_prompt=' + (opt_forceInteractive ? 'force' : 'auto')
];
w = window.open(this.endpoint + "auth" + queryparams.join('&'));
}
}
});