forked from linagora/jmap-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate accounts+capabilities to new JMAP authentication spec
According to the recent updates to the JMAP spec, account data is now loaded from the authentication response. Therefore the AuthAccess model was significantly changed to serve as a container for authentication data, account information and server capabilities. This change requires authentication responses to comply with the latest spec as the model requires certain new properties to be present. Added: jmap.ServerCapablities Removed: jmap.AccountCapabilities The namespace URIs used for the various capabilites are defined in jmap.Constants but not yet final. see links in issue linagora#58
- Loading branch information
1 parent
3812ff4
commit b6eb18b
Showing
16 changed files
with
495 additions
and
222 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 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 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 |
---|---|---|
@@ -1,29 +1,65 @@ | ||
'use strict'; | ||
|
||
import Model from './Model.js'; | ||
import Utils from '../utils/Utils.js'; | ||
import Constants from '../utils/Constants.js'; | ||
import Account from './Account.js'; | ||
import ServerCapabilities from './ServerCapabilities.js'; | ||
import MailCapabilities from './MailCapabilities.js'; | ||
import JSONBuilder from '../utils/JSONBuilder.js'; | ||
|
||
export default class AuthAccess { | ||
export default class AuthAccess extends Model { | ||
/** | ||
* This class represents a JMAP [Auth Access Response]{@link http://jmap.io/spec.html#authentication}. | ||
* This class represents a JMAP [Auth Access Response]{@link http://jmap.io/spec-core.html#201-authentication-is-complete-access-token-created}. | ||
* | ||
* @constructor | ||
* | ||
* @param jmap {Client} The {@link Client} instance that created this _AuthAccess_. | ||
* @param payload {Object} The server response of an auth access request. | ||
*/ | ||
constructor(jmap, payload) { | ||
super(jmap); | ||
|
||
constructor(payload) { | ||
Utils.assertRequiredParameterIsPresent(payload, 'payload'); | ||
['username', 'accessToken', 'apiUrl', 'eventSourceUrl', 'uploadUrl', 'downloadUrl'].forEach((property) => { | ||
['username', 'accessToken', 'signingId', 'signingKey', 'apiUrl', 'eventSourceUrl', 'uploadUrl', 'downloadUrl', 'accounts', 'capabilities'].forEach((property) => { | ||
Utils.assertRequiredParameterIsPresent(payload[property], property); | ||
}); | ||
|
||
this.username = payload.username; | ||
this.versions = payload.versions || []; | ||
this.extensions = payload.extensions || {}; | ||
this.accessToken = payload.accessToken; | ||
this.signingId = payload.signingId; | ||
this.signingKey = payload.signingKey; | ||
this.apiUrl = payload.apiUrl; | ||
this.eventSourceUrl = payload.eventSourceUrl; | ||
this.uploadUrl = payload.uploadUrl; | ||
this.downloadUrl = payload.downloadUrl; | ||
this.capabilities = payload.capabilities; | ||
this.serverCapabilities = new ServerCapabilities(this.capabilities[Constants.CORE_CAPABILITIES_URI] || {}); | ||
this.mailCapabilities = new MailCapabilities(this.capabilities[Constants.MAIL_CAPABILITIES_URI] || {}); | ||
|
||
this.accounts = {}; | ||
for (var accountId in payload.accounts) { | ||
this.accounts[accountId] = Account.fromJSONObject(jmap, Object.assign({ id: accountId }, payload.accounts[accountId])); | ||
} | ||
} | ||
|
||
/** | ||
* Creates a JSON representation from this {@link AuthAccess}. | ||
* | ||
* @return JSON object with only owned properties and non-null default values. | ||
*/ | ||
toJSONObject() { | ||
return new JSONBuilder() | ||
.append('username', this.username) | ||
.append('accessToken', this.accessToken) | ||
.append('signingId', this.signingId) | ||
.append('signingKey', this.signingKey) | ||
.append('apiUrl', this.apiUrl) | ||
.append('eventSourceUrl', this.eventSourceUrl) | ||
.append('uploadUrl', this.uploadUrl) | ||
.append('downloadUrl', this.downloadUrl) | ||
.appendObject('accounts', this.accounts) | ||
.appendObject('capabilities', this.capabilities) | ||
.build(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
'use strict'; | ||
|
||
import Utils from '../utils/Utils.js'; | ||
|
||
export default class Capabilities { | ||
/** | ||
* This class represents an abstract JMAP "capabilities" object. See {@link http://jmap.io/spec.html#accounts*}.<br /> | ||
* It is subclassed in more specific xxxCapabilities classes. | ||
* This class represents an generic JMAP "capabilities" object. See {@link http://jmap.io/spec-core.html#getting-an-access-token*}.<br /> | ||
* | ||
* @param [opts] {Object} The optional properties of this _AccountCapabilities_. | ||
* @param [opts.isReadOnly=false] {Boolean} Whether the feature denoted by this _Capabilities_ instance is read-only. | ||
* @param namespace {String} The namespace/identifier of the capabilities. | ||
* @param [opts] {Object} The optional properties of this _Capabilities_. | ||
*/ | ||
constructor(opts) { | ||
constructor(namespace, opts) { | ||
Utils.assertRequiredParameterIsPresent(namespace, 'namespace'); | ||
|
||
opts = opts || {}; | ||
|
||
this.isReadOnly = !!opts.isReadOnly; | ||
this.ns = namespace; | ||
Object.assign(this, opts); | ||
} | ||
} |
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 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,30 @@ | ||
'use strict'; | ||
|
||
export default class ServerCapabilities { | ||
/** | ||
* This class represents a JMAP [ServerCapabilities]{@link http://jmap.io/spec-core.html#201-authentication-is-complete-access-token-created}.<br /> | ||
* An _ServerCapabilities_ object describes general capabilities of a JMAP server. | ||
* | ||
* @constructor | ||
* | ||
* @param [opts] {Object} The optional properties of this _ServerCapabilities_. | ||
* @param [opts.maxSizeUpload=0] {Number} The maximum file size, in bytes, that the server will accept for a single file upload. | ||
* @param [opts.maxSizeRequest=0] {Number} The maximum size, in bytes, that the server will accept for a single request to the API endpoint. | ||
* @param [opts.maxConcurrentUpload=1] {Number} The maximum number of concurrent requests the server will accept to the upload endpoint. | ||
* @param [opts.maxConcurrentRequests=1] {Number} The maximum number of concurrent requests the server will accept to the API endpoint. | ||
* @param [opts.maxCallsInRequest=1] {Number} The maximum number of method calls the server will accept in a single request to the API endpoint. | ||
* @param [opts.maxObjectsInGet=0] {Number} The maximum number of objects that the client may request in a single getXXX type method call. | ||
* @param [opts.maxObjectsInSet=0] {Number} The maximum number of objects the client may send to create, update or destroy in a single setXXX type method call. | ||
*/ | ||
constructor(opts) { | ||
opts = opts || {}; | ||
|
||
this.maxSizeUpload = opts.maxSizeUpload || 0; | ||
this.maxSizeRequest = opts.maxSizeRequest || 0; | ||
this.maxConcurrentUpload = opts.maxConcurrentUpload || 1; | ||
this.maxConcurrentRequests = opts.maxConcurrentRequests || 1; | ||
this.maxCallsInRequest = opts.maxCallsInRequest || 1; | ||
this.maxObjectsInGet = opts.maxObjectsInGet || 0; | ||
this.maxObjectsInSet = opts.maxObjectsInSet || 0; | ||
} | ||
} |
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
Oops, something went wrong.