Permalink
Browse files

Add YakServer authentication

  • Loading branch information...
1 parent b79aec9 commit 6537c2ab9b26d7998da5d0054f3d3f71468346a7 @decklin committed Jan 11, 2010
Showing with 33 additions and 1 deletion.
  1. +1 −0 background.html
  2. +9 −1 background.js
  3. +2 −0 bindings/yakedit.js
  4. +15 −0 options.html
  5. +6 −0 options.js
View
@@ -1,2 +1,3 @@
<script src="common/config.js"></script>
+<script src="base64.js"></script>
<script src="background.js"></script>
View
@@ -4,7 +4,9 @@ config.defaults({
bindingFiles: ['bindings/base.js', 'bindings/emacs.js'],
urlEnabled: false,
bindingUrl: 'http://localhost:2562/bindings.js',
- bindingText: ''
+ bindingText: '',
+ username: '',
+ password: ''
});
// The callback here might be a real function in our environment, or
@@ -24,6 +26,12 @@ function xhr(req, callback) {
xhr.setRequestHeader(h, req.headers[h]);
}
+ if (req.authenticate) {
+ var creds = config.get('username') + ':' + config.get('password');
+ var auth = 'Basic ' + Base64.encode(creds);
+ xhr.setRequestHeader('Authorization', auth);
+ }
+
xhr.onreadystatechange = function() {
if (this.readyState === 4)
callback.call(this, this);
View
@@ -13,6 +13,7 @@ yak.bindings.add({
var req = {
method: 'POST',
url: url,
+ authenticate: true,
data: this.value
};
yak.xhr(req, function() {
@@ -25,6 +26,7 @@ yak.bindings.add({
yak.xhr({
method: 'POST',
url: 'http://localhost:2562/style/edit',
+ authenticate: true,
data: {url: location.href}
});
}
View
@@ -61,6 +61,21 @@
YakServer won't work.
</p>
<textarea id="bindingText" cols="80"></textarea>
+ <h2>Authentication</h2>
+ <p>
+ If you're using YakServer, enter the username and password you set
+ for it here.
+ </p>
+ <table>
+ <tr>
+ <td>Username:</td>
+ <td><input type="text" id="username" /></td>
+ </tr>
+ <tr>
+ <td>Password:</td>
+ <td><input type="password" id="password" /></td>
+ </tr>
+ </table>
<div class="actions">
<p>
<input type="button" value="Save Options" onclick="save();" />
View
@@ -26,6 +26,9 @@ function init() {
$('bindingText').value = config.get('bindingText');
$('bindingText').rows = nRows(config.get('bindingText'));
+
+ $('username').value = config.get('username');
+ $('password').value = config.get('password');
}
function save() {
@@ -40,6 +43,9 @@ function save() {
config.set('bindingText', $('bindingText').value);
+ config.set('username', $('username').value);
+ config.set('password', $('password').value);
+
var reloadPort = chrome.extension.connect({name: 'reloadBindings'});
reloadPort.postMessage(null);
}

0 comments on commit 6537c2a

Please sign in to comment.