forked from mainmatter/ember-simple-auth-component
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-auth-torii.js
200 lines (168 loc) · 5.85 KB
/
simple-auth-torii.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
(function(global) {
Ember.libraries.register('Ember Simple Auth Torii', '0.8.0');
var define, requireModule;
(function() {
var registry = {}, seen = {};
define = function(name, deps, callback) {
registry[name] = { deps: deps, callback: callback };
};
requireModule = function(name) {
if (seen.hasOwnProperty(name)) { return seen[name]; }
seen[name] = {};
if (!registry[name]) {
throw new Error("Could not find module " + name);
}
var mod = registry[name],
deps = mod.deps,
callback = mod.callback,
reified = [],
exports;
for (var i=0, l=deps.length; i<l; i++) {
if (deps[i] === 'exports') {
reified.push(exports = {});
} else {
reified.push(requireModule(resolve(deps[i])));
}
}
var value = callback.apply(this, reified);
return seen[name] = exports || value;
function resolve(child) {
if (child.charAt(0) !== '.') { return child; }
var parts = child.split("/");
var parentBase = name.split("/").slice(0, -1);
for (var i=0, l=parts.length; i<l; i++) {
var part = parts[i];
if (part === '..') { parentBase.pop(); }
else if (part === '.') { continue; }
else { parentBase.push(part); }
}
return parentBase.join("/");
}
};
requireModule.registry = registry;
})();
define("simple-auth-torii/authenticators/torii",
["simple-auth/authenticators/base","exports"],
function(__dependency1__, __exports__) {
"use strict";
var Base = __dependency1__["default"];
/**
Authenticator that wraps the
[Torii library](https://github.com/Vestorly/torii).
_The factory for this authenticator is registered as
`'simple-auth-authenticator:torii'` in Ember's container._
@class Torii
@namespace SimpleAuth.Authenticators
@module simple-auth-torii/authenticators/torii
@extends Base
*/
__exports__["default"] = Base.extend({
/**
@property torii
@private
*/
torii: null,
/**
@property provider
@private
*/
provider: null,
/**
Restores the session by calling the torii provider's `fetch` method.
@method restore
@param {Object} data The data to restore the session from
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session being authenticated
*/
restore: function(data) {
var _this = this;
data = data || {};
return new Ember.RSVP.Promise(function(resolve, reject) {
if (!Ember.isEmpty(data.provider)) {
var provider = data.provider;
_this.torii.fetch(data.provider, data).then(function(data) {
_this.resolveWith(provider, data, resolve);
}, function() {
delete _this.provider;
reject();
});
} else {
delete _this.provider;
reject();
}
});
},
/**
Authenticates the session by opening the torii provider. For more
documentation on torii, see the
[project's README](https://github.com/Vestorly/torii#readme).
@method authenticate
@param {String} provider The provider to authenticate the session with
@param {Object} options The options to pass to the torii provider
@return {Ember.RSVP.Promise} A promise that resolves when the provider successfully authenticates a user and rejects otherwise
*/
authenticate: function(provider, options) {
var _this = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
_this.torii.open(provider, options || {}).then(function(data) {
_this.resolveWith(provider, data, resolve);
}, reject);
});
},
/**
Closes the torii provider.
@method invalidate
@param {Object} data The data that's stored in the session
@return {Ember.RSVP.Promise} A promise that resolves when the provider successfully closes and rejects otherwise
*/
invalidate: function(data) {
var _this = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
_this.torii.close(_this.provider).then(function() {
delete _this.provider;
resolve();
}, reject);
});
},
/**
@method resolveWith
@private
*/
resolveWith: function(provider, data, resolve) {
data.provider = provider;
this.provider = data.provider;
resolve(data);
}
});
});
define("simple-auth-torii/ember",
["./initializer"],
function(__dependency1__) {
"use strict";
var initializer = __dependency1__["default"];
Ember.onLoad('Ember.Application', function(Application) {
Application.initializer(initializer);
});
});
define("simple-auth-torii/initializer",
["simple-auth-torii/authenticators/torii","exports"],
function(__dependency1__, __exports__) {
"use strict";
var Authenticator = __dependency1__["default"];
__exports__["default"] = {
name: 'simple-auth-torii',
before: 'simple-auth',
after: 'torii',
initialize: function(container, application) {
var torii = container.lookup('torii:main');
var authenticator = Authenticator.create({ torii: torii });
application.register('simple-auth-authenticator:torii', authenticator, { instantiate: false });
}
};
});
define('simple-auth/authenticators/base', ['exports'], function(__exports__) {
__exports__['default'] = global.SimpleAuth.Authenticators.Base;
});
var Authenticator = requireModule('simple-auth-torii/authenticators/torii')['default'];
global.SimpleAuth.Authenticators.Torii = Authenticator;
requireModule('simple-auth-torii/ember');
})((typeof global !== 'undefined') ? global : window);