Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK updates #118

Merged
merged 14 commits into from
Mar 25, 2024
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,34 @@ app.get('/authenticatedRoute', passageAuthMiddleware, async (req, res) => {
});
```

## Retrieve User Info By Identifier

To retrieve information about a user, you could also use the `passage.user.getUserByIdentifier()` function. You will need to use a Passage API key, which can be created in the Passage Console under your Application Settings. This API key grants your web server access to the Passage management APIs to get and update information about users. This API key must be protected and stored in an appropriate secure storage location. It should never be hard-coded in the repository.

```javascript
import Passage from '@passageidentity/passage-node';
import express from 'express';

const app = express();
const port = 3000;

let passageConfig = {
appID: 'YOUR_APP_ID',
apiKey: 'YOUR_API_KEY',
};
let passage = new Passage(passageConfig);

// example authenticated route
app.get('/authenticatedRoute', passageAuthMiddleware, async (req, res) => {
// get passage user identifier from middleware
let userIdentifier = res.userIdentifier;

// get user info
let passageUser = await passage.user.getUserByIdentifier(userIdentifier);
console.log(passageUser.email);
});
```

## Activate/Deactivate User

You can also activate or deactivate a user using the Passage SDK. These actions require an API Key and deactivating a user will prevent them from logging into your application with Passage.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Added new method to get user by identifier, getUserByIdentifier",
"packageName": "@passageidentity/passage-node",
"email": "[email protected]",
"dependentChangeType": "patch"
}
73 changes: 48 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"babel-jest": "^27.2.0",
"beachball": "^2.37.0",
"dotenv": "^10.0.0",
"eslint": "^8.5.0",
"eslint": "^8.57.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
Expand All @@ -24,7 +24,8 @@
"supertest": "^6.1.6",
"ts-jest": "^27.0.5",
"ts-node-dev": "^2.0.0",
"typescript": "^4.4.3"
"typescript": "^4.4.3",
"@faker-js/faker": "^8.4.1"
},
"name": "@passageidentity/passage-node",
"main": "./lib/cjs/index.js",
Expand Down
28 changes: 28 additions & 0 deletions src/classes/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,34 @@ export default class User {
}
}

/**
* Get a user's object using their user identifier.
*
* @param {string} identifier The Passage user email or phone number
* @return {Promise<UserInfo>} Passage User object
*/
async getUserByIdentifier(identifier: string): Promise<UserInfo> {
this._apiKeyCheck();

try {
const response = await this.#client.listPaginatedUsers({
appId: this.#appID,
limit: 1,
identifier: identifier.toLowerCase(),
});

const users = response.users;
if (!users.length) {
throw new PassageError('Could not find user with that identifier.');
}

return this.get(users[0].id);

} catch (err) {
throw new PassageError('Could not fetch user by identifier.', err as ResponseError);
}
}

/**
* Deactivate a user using their user ID.
*
Expand Down
10 changes: 7 additions & 3 deletions src/generated/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,28 @@ models/GithubUserSocialConnection.ts
models/GoogleUserSocialConnection.ts
models/LayoutConfig.ts
models/Layouts.ts
models/Link.ts
models/ListDevicesResponse.ts
models/ListPaginatedUsersItem.ts
models/ListPaginatedUsersResponse.ts
models/MagicLink.ts
models/MagicLinkAuthMethod.ts
models/MagicLinkChannel.ts
models/MagicLinkResponse.ts
models/MagicLinkType.ts
models/Model400Error.ts
models/Model401Error.ts
models/Model403Error.ts
models/Model404Error.ts
models/Model500Error.ts
models/Nonce.ts
models/OtpAuthMethod.ts
models/PaginatedLinks.ts
models/PasskeysAuthMethod.ts
models/Technologies.ts
models/TtlDisplayUnit.ts
models/UpdateMagicLinkAuthMethod.ts
models/UpdateOtpAuthMethod.ts
models/UpdatePasskeysAuthMethod.ts
models/UpdateUserRequest.ts
models/UserEventStatus.ts
models/UserInfo.ts
models/UserMetadataField.ts
models/UserMetadataFieldType.ts
Expand Down
3 changes: 3 additions & 0 deletions src/generated/apis/MagicLinksApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
MagicLinkResponse,
Model400Error,
Model401Error,
Model403Error,
Model404Error,
Model500Error,
} from '../models/index';
Expand All @@ -31,6 +32,8 @@ import {
Model400ErrorToJSON,
Model401ErrorFromJSON,
Model401ErrorToJSON,
Model403ErrorFromJSON,
Model403ErrorToJSON,
Model404ErrorFromJSON,
Model404ErrorToJSON,
Model500ErrorFromJSON,
Expand Down
3 changes: 3 additions & 0 deletions src/generated/apis/TokensApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
import * as runtime from '../runtime';
import type {
Model401Error,
Model403Error,
Model404Error,
Model500Error,
} from '../models/index';
import {
Model401ErrorFromJSON,
Model401ErrorToJSON,
Model403ErrorFromJSON,
Model403ErrorToJSON,
Model404ErrorFromJSON,
Model404ErrorToJSON,
Model500ErrorFromJSON,
Expand Down
Loading
Loading