-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
service and app auth providers introduced
- Loading branch information
Showing
5 changed files
with
111 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
var inherits = require('util').inherits; | ||
var AuthProvider = require('authen/lib/auth_provider'); | ||
|
||
|
||
var AppAuthProvider = function (opt_options) { | ||
AuthProvider.call(this, opt_options); | ||
}; | ||
inherits(AppAuthProvider, AuthProvider); | ||
|
||
|
||
AppAuthProvider.prototype.packIdentity = function (identity) { | ||
return JSON.stringify([identity.service, identity.user]); | ||
}; | ||
|
||
AppAuthProvider.prototype.unpackIdentity = function (identityStr) { | ||
var parsed = JSON.parse(identityStr); | ||
return { | ||
service: parsed[0], | ||
user: parsed[1] | ||
}; | ||
}; | ||
|
||
AppAuthProvider.prototype.prepareAuthResult = function (ctx, options, authResult, cb) { | ||
var identity = this.getIdentity(authResult); | ||
var result = { | ||
type: identity.authType || this.defaultAuthType, | ||
identity: identity.user, | ||
via: { | ||
type: this.type, | ||
identity: identity.service, | ||
authResult: authResult | ||
} | ||
}; | ||
cb(null, result); | ||
}; | ||
|
||
|
||
module.exports = AppAuthProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"use strict"; | ||
var ServiceAuthProvider = require('./service'); | ||
var AppAuthProvider = require('./app'); | ||
|
||
|
||
module.exports = { | ||
Service: ServiceAuthProvider, | ||
App: AppAuthProvider | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"use strict"; | ||
var inherits = require('util').inherits; | ||
var AuthProvider = require('authen/lib/auth_provider'); | ||
|
||
|
||
var ServiceAuthProvider = function (opt_options) { | ||
AuthProvider.call(this, opt_options); | ||
}; | ||
inherits(ServiceAuthProvider, AuthProvider); | ||
|
||
|
||
ServiceAuthProvider.prototype.prepareAuthResult = function (ctx, options, authResult, cb) { | ||
var result = { | ||
type: this.type, | ||
identity: this.getIdentity(authResult), | ||
authResult: result | ||
}; | ||
if (options.allowOnBehalf && this.options.allowOnBehalf) { | ||
var onBehalf = this.createOnBehalfResult(ctx); | ||
if (onBehalf != null) { | ||
var via = result; | ||
result = onBehalf; | ||
result.via = via; | ||
} | ||
} | ||
cb(null, result); | ||
}; | ||
|
||
ServiceAuthProvider.prototype.unpackOnBehalfIdentity = function (identityStr) { | ||
return identityStr; | ||
}; | ||
|
||
ServiceAuthProvider.prototype.createOnBehalfResult = function (ctx) { | ||
var result = null; | ||
var onBehalfData = this.adapter.extractOnBehalfData(ctx); | ||
if (onBehalfData != null) { | ||
result = { | ||
type: onBehalfData.type || this.options.defaultOnBehalfAuthType, | ||
identity: this.unpackOnBehalfIdentity(onBehalfData.identityStr), | ||
onBehalfData: onBehalfData | ||
}; | ||
} | ||
return result; | ||
}; | ||
|
||
|
||
module.exports = ServiceAuthProvider; |