| 47 | * @module AuthorizationGrantsApi |
| 48 | */ |
| 49 | const authorizationGrants = (client) => ({ |
| 50 | /** |
| 51 | * @typedef {Object} AccessTokenGuardData |
| 52 | * |
| 53 | * @property {String} id |
| 54 | * Unique identifier of an access token |
| 55 | */ |
| 56 | |
| 57 | /** |
| 58 | * @typedef {Object} X509GuardData |
| 59 | * x509 certificates are identified by their Subject attribute. You can |
| 60 | * configure the guard by specifying values for the Subject's sub-attributes, |
| 61 | * such as CN or OU. If a certificate's Subject contains all of the |
| 62 | * sub-attribute values specified in the guard, the guard will produce a |
| 63 | * positive match. |
| 64 | * |
| 65 | * @property {Object} subject - Object identifying key-value pairs in the subject field. |
| 66 | * @property {(String|Array)} subject.C - Country attribute |
| 67 | * @property {(String|Array)} subject.O - Organization attribute |
| 68 | * @property {(String|Array)} subject.OU - Organizational Unit attribute |
| 69 | * @property {(String|Array)} subject.L - Locality attribute |
| 70 | * @property {(String|Array)} subject.ST - State/Province attribute |
| 71 | * @property {(String|Array)} subject.STREET - Street Address attribute |
| 72 | * @property {(String|Array)} subject.POSTALCODE - Postal Code attribute |
| 73 | * @property {String} subject.SERIALNUMBER - Serial Number attribute |
| 74 | * @property {String} subject.CN - Common Name attribute |
| 75 | */ |
| 76 | |
| 77 | /** |
| 78 | * Create a new access grant. |
| 79 | * |
| 80 | * @param {Object} params - Parameters for access grant creation. |
| 81 | * @param {String} params.guardType - Type of credential to guard with, either 'access_token' or 'x509'. |
| 82 | * @param {Object} params.guardData - Object containing data needed to identify the incoming credential. |
| 83 | * @param {String} params.policy - Authorization polciy to attach to specific grant. See {@link AuthorizationGrant} for a list of available policiies. |
| 84 | * @param {objectCallback} [callback] - Optional callback. Use instead of Promise return value as desired. |
| 85 | * @returns {Promise<Object>} Success message or error. |
| 86 | */ |
| 87 | create: (params, cb) => { |
| 88 | params = Object.assign({}, params) |
| 89 | if (params.guardType == 'x509') { |
| 90 | params.guardData = util.sanitizeX509GuardData(params.guardData) |
| 91 | } |
| 92 | |
| 93 | return shared.create( |
| 94 | client, |
| 95 | '/create-authorization-grant', |
| 96 | params, |
| 97 | {skipArray: true, cb} |
| 98 | ) |
| 99 | }, |
| 100 | |
| 101 | /** |
| 102 | * Delete the specfiied access grant. |
| 103 | * |
| 104 | * @param {Object} params - Parameters for access grant deletion. |
| 105 | * @param {String} params.guardType - Type of credential to delete, either 'access_token' or 'x509'. |
| 106 | * @param {Object} params.guardData - Object containing data needed to identify the credential to be removed. |