Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ You can also use the pre-built browser version located in the `dist/` directory:

To configure the library:

1. Create an application in the MIRACL Trust platform. For information about how
to do it, see the
1. Create an account in the MIRACL Trust platform. For information about how to
do it, see the
[Getting Started](https://miracl.com/resources/docs/guides/get-started/)
guide.
2. Create a new instance of MIRACLTrust and pass the configuration as an object:
Expand Down
23 changes: 4 additions & 19 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parseUriParams, uriEncode } from "./uri.js";
import Crypto from "./crypto.js";
import HTTP from "./http.js";
import { parseUriParams } from "./uri.js";
import Users from "./users.js";

/**
Expand All @@ -11,12 +11,6 @@ import Users from "./users.js";
* @param {string} options.seed - Hex-encoded random number generator seed
* @param {string} options.deviceName - Name of the current device
* @param {Object} options.userStorage - Storage for saving user data
* @param {Object} options.oidc - Parameters for initializing an OIDC auth session
* @param {string} options.oidc.client_id - OIDC Client ID
* @param {string} options.oidc.redirect_uri - OIDC redirect URI
* @param {string} options.oidc.response_type - OIDC response type. Only 'code' is supported
* @param {string} options.oidc.scope - OIDC scope. Must include 'openid'
* @param {string} options.oidc.state - OIDC state
* @param {bool} options.cors - Enable CORS requests if set to 'true'
* @param {number} options.requestTimeout - Time before an HTTP request times out in milliseconds
* @param {string} options.applicationInfo - Set additional information that will be sent via X-MIRACL-CLIENT HTTP header
Expand Down Expand Up @@ -50,10 +44,6 @@ export default function Client(options) {
options.requestTimeout = 4000;
}

if (!options.oidc) {
options.oidc = {};
}

// Set the client name using the current lib version and provided application info
options.clientName = "MIRACL Client.js/8.13.0" + (options.applicationInfo ? " " + options.applicationInfo : "");

Expand Down Expand Up @@ -149,9 +139,10 @@ Client.prototype.sendPushNotificationForAuth = function (userId, callback) {
}

const reqData = {
url: this.options.projectUrl + "/pushauth?" + uriEncode(this.options.oidc),
url: this.options.projectUrl + "/pushauth",
type: "POST",
data: {
projectId: this.options.projectId,
prerollId: userId
}
};
Expand Down Expand Up @@ -187,16 +178,10 @@ Client.prototype.sendVerificationEmail = function (userId, callback) {
type: "POST",
data: {
userId: userId,
mpinId: this.users.get(userId, "mpinId"),
projectId: this.options.projectId,
accessId: this.session.accessId,
deviceName: this._getDeviceName(),
deviceTag: this._getDeviceTag(),
clientId: this.options.oidc["client_id"],
redirectURI: this.options.oidc["redirect_uri"],
scope: this.options.oidc["scope"] ? this.options.oidc["scope"].split(" ") : [],
state: this.options.oidc["state"],
nonce: this.options.oidc["nonce"]
deviceTag: this._getDeviceTag()
}
};

Expand Down
12 changes: 0 additions & 12 deletions src/uri.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
export function uriEncode (obj) {
const str = [];

for (const p in obj) {
if (Object.prototype.hasOwnProperty.call(obj, p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
}

return str.join("&");
}

export function parseUriParams (uri) {
const query = uri.split("?").pop();
const queryArr = query.split("&");
Expand Down
9 changes: 2 additions & 7 deletions test/test-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,14 @@ describe("Client sendPushNotificationForAuth", () => {
let client;

before(() => {
const config = testConfig();
config.oidc = {
client_id: "testClientID" // eslint-disable-line camelcase
};
client = new Client(config);
client = new Client(testConfig());
});

it("should make a request to the pushauth endpoint", () => {
const requestStub = sinon.stub(client.http, "request").yields(null, { webOTT: "test" });
sinon.stub(client.http, "request").yields(null, { webOTT: "test" });

client.sendPushNotificationForAuth("test@example.com", (err, data) => {
expect(data).to.exist;
expect(requestStub.firstCall.args[0].url).to.equal("https://project.miracl.io/pushauth?client_id=testClientID");
expect(data.webOTT).to.equal("test");
});
});
Expand Down
Loading