| 
									
										
										
										
											2017-02-20 15:22:48 -07:00
										 |  |  | ;(function (exports) { | 
					
						
							|  |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 00:44:14 -07:00
										 |  |  |   var OAUTH3 = exports.OAUTH3 = exports.OAUTH3 || require('./oauth3.core.js').OAUTH3; | 
					
						
							| 
									
										
										
										
											2017-02-21 11:49:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-20 15:22:48 -07:00
										 |  |  |   OAUTH3.authn.resourceOwnerPassword = OAUTH3.authz.resourceOwnerPassword = function (directive, opts) { | 
					
						
							|  |  |  |     var providerUri = directive.issuer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (opts.mockError) { | 
					
						
							|  |  |  |       return OAUTH3.PromiseA.resolve({data: {error_description: "fake error", error: "errorcode", error_uri: "https://blah"}}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return OAUTH3._mockToken(providerUri, opts); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2017-02-21 20:18:14 -05:00
										 |  |  |   OAUTH3.authn.loginMeta = function (directive, opts) { | 
					
						
							|  |  |  |     if (opts.mockError) { | 
					
						
							|  |  |  |       return OAUTH3.PromiseA.resolve({ data: { error: { message: "Yikes!", code: 'E' } } }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return OAUTH3.PromiseA.resolve({ data: {} }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   OAUTH3.authn.otp = function (directive, opts) { | 
					
						
							|  |  |  |     if (opts.mockError) { | 
					
						
							|  |  |  |       return OAUTH3.PromiseA.resolve({data: {error: {message: "Yikes!", code: 'E'}}}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return OAUTH3.PromiseA.resolve({data: {uuid: "uuidblah"}}); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2017-02-20 15:22:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 20:18:14 -05:00
										 |  |  |   OAUTH3.authz.scopes = function () { | 
					
						
							| 
									
										
										
										
											2017-03-07 14:55:27 -07:00
										 |  |  |     return OAUTH3.PromiseA.resolve({ | 
					
						
							| 
									
										
										
										
											2017-02-21 20:18:14 -05:00
										 |  |  |       pending: ['oauth3_authn']   // not yet accepted
 | 
					
						
							|  |  |  |     , granted: []                 // all granted, ever
 | 
					
						
							|  |  |  |     , requested: ['oauth3_authn'] // all requested, now
 | 
					
						
							|  |  |  |     , accepted: []                // granted (ever) and requested (now)
 | 
					
						
							| 
									
										
										
										
											2017-03-07 14:55:27 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-02-21 20:18:14 -05:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2017-02-20 15:22:48 -07:00
										 |  |  |   OAUTH3.authz.grants = function (providerUri, opts) { | 
					
						
							|  |  |  |     if ('POST' === opts.method) { | 
					
						
							|  |  |  |       return OAUTH3._mockToken(providerUri, opts); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return OAUTH3.discover(providerUri, { | 
					
						
							|  |  |  |       client_id: providerUri | 
					
						
							|  |  |  |     , debug: opts.debug | 
					
						
							|  |  |  |     }).then(function (directive) { | 
					
						
							|  |  |  |       return { | 
					
						
							|  |  |  |         client: { | 
					
						
							|  |  |  |           name: "foo" | 
					
						
							|  |  |  |         , client_id: "localhost.foo.daplie.me:8443" | 
					
						
							|  |  |  |         , url: "https://localhost.foo.daplie.me:8443" | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       , grants: [] | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   OAUTH3._refreshToken = function (providerUri, opts) { | 
					
						
							|  |  |  |     return OAUTH3._mockToken(providerUri, opts); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   OAUTH3._mockToken = function (providerUri, opts) { | 
					
						
							| 
									
										
										
										
											2017-03-06 15:13:29 -07:00
										 |  |  |     var payload = { exp: Math.round(Date.now() / 1000) + 900, sub: 'fakeUserId', scp: opts.scope }; | 
					
						
							|  |  |  |     return OAUTH3.crypto._signPayload(payload).then(function (accessToken) { | 
					
						
							|  |  |  |       return OAUTH3.hooks.session.refresh( | 
					
						
							|  |  |  |         opts.session || { | 
					
						
							|  |  |  |           provider_uri: providerUri | 
					
						
							|  |  |  |         , client_id: opts.client_id | 
					
						
							|  |  |  |         , client_uri: opts.client_uri || opts.clientUri | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       , { access_token: accessToken | 
					
						
							|  |  |  |         , refresh_token: accessToken | 
					
						
							|  |  |  |         , expires_in: "900" | 
					
						
							|  |  |  |         , scope: opts.scope | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2017-02-20 15:22:48 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 11:49:41 -07:00
										 |  |  | }('undefined' !== typeof exports ? exports : window)); |