Skip to content

Commit

Permalink
Merge pull request #10 from eddiemoore/ie-login-fix
Browse files Browse the repository at this point in the history
Changed postMessage to localStorage to fix #8
  • Loading branch information
eddiemoore committed Nov 20, 2014
2 parents 8191f72 + e538b3a commit 52a1e8e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
25 changes: 25 additions & 0 deletions examples/callback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
var target = window.self === window.top ? window.opener : window.parent;

var hash = window.location.hash;
if (hash) {
var token = window.location.hash.split('&')[0].split('=')[1];
// target.postMessage(token, 'http://example.com/');
localStorage.setItem('spotify-token', token);
}

}//]]>

</script>
</head>
<body>

</body>
</html>
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html ng-app="example">
<html ng-app="exampleApp">
<head>
<title>angular-spotify demo!</title>
<style>
Expand Down
12 changes: 7 additions & 5 deletions examples/main.controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
angular
.module('example', ['spotify'])
.module('exampleApp', ['spotify'])
.config(function (SpotifyProvider) {
console.log(SpotifyProvider);
SpotifyProvider.setClientId('123456789');
SpotifyProvider.setRedirectUri('http://www.example.com/callback.html');
SpotifyProvider.setClientId('123456789123456789');
SpotifyProvider.setRedirectUri('http://example.com/callback.html');
SpotifyProvider.setScope('playlist-read-private');
})
.controller('MainController', ['$scope', 'Spotify', function ($scope, Spotify) {
Expand All @@ -15,7 +14,10 @@ angular
};

$scope.login = function () {
Spotify.login();
Spotify.login().then(function (data) {
console.log(data);
alert("You are now logged in");
})
};

// Gets an album
Expand Down
20 changes: 12 additions & 8 deletions src/angular-spotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,20 +383,24 @@
var authWindow = window.open(
'https://accounts.spotify.com/authorize?' + this.toQueryString(params),
'Spotify',
'menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=' + w + ',height=' + h + ',top=' + top + ',left=' + left
'menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=' + w + ',height=' + h + ',top=' + top + ',left=' + left
);

function receiveMessage (event) {
if (authWindow) {
authWindow.close();
}
function storageChanged (e) {
if (e.key === 'spotify-token') {
if (authWindow) {
authWindow.close();
}

that.setAuthToken(event.data);
that.setAuthToken(e.newValue);
$window.removeEventListener('storage', storageChanged, false);
localStorage.removeItem('spotify-token');

deferred.resolve(event.data);
deferred.resolve(event.data);
}
}

$window.addEventListener('message', receiveMessage, false);
$window.addEventListener('storage', storageChanged, false);

return deferred.promise;
};
Expand Down

0 comments on commit 52a1e8e

Please sign in to comment.