https://github.com/dfinity/icp-js-auth
Authentication library for Internet Computer web apps
https://github.com/dfinity/icp-js-auth
authentication br-protected-1 icp internet-computer internet-identity typescript
Last synced: 7 months ago
JSON representation
Authentication library for Internet Computer web apps
- Host: GitHub
- URL: https://github.com/dfinity/icp-js-auth
- Owner: dfinity
- License: apache-2.0
- Created: 2025-09-22T14:37:22.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-10-03T11:54:13.000Z (7 months ago)
- Last Synced: 2025-10-03T13:32:05.917Z (7 months ago)
- Topics: authentication, br-protected-1, icp, internet-computer, internet-identity, typescript
- Language: TypeScript
- Homepage: https://js.icp.build/auth
- Size: 238 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# @icp-sdk/auth
[](https://www.npmjs.com/package/@icp-sdk/auth)
[](https://opensource.org/licenses/Apache-2.0)
Authentication library for Internet Computer web apps.
> Still using `@dfinity/auth-client`? Migrate to [`@icp-sdk/auth`](https://js.icp.build/auth/latest/upgrading/v4)!
---
## Installation
You can install the `@icp-sdk/auth` package with your package manager of choice:
### npm
```shell
npm install @icp-sdk/auth
```
### pnpm
```shell
pnpm add @icp-sdk/auth
```
### yarn
```shell
yarn add @icp-sdk/auth
```
> Note: this package is only meant to be used in **browser** environments.
## Usage Example
Here's a simple example of how to use the `@icp-sdk/auth` package to authenticate a user with Internet Identity on an Internet Computer web app:
```typescript
import { AuthClient } from '@icp-sdk/auth/client';
const identityProvider = 'https://id.ai/';
const authClient = await AuthClient.create();
const identity = authClient.getIdentity(); // At this point, you'll get a Principal.anonymous()
async function onSuccess() {
console.log('Login successful');
const identity = authClient.getIdentity(); // At this point, you'll get an authenticated identity
console.log(authClient.isAuthenticated()); // true
}
await authClient.login({
identityProvider,
onSuccess,
});
// later in your app
await authClient.logout();
```
Additional documentation can be found [here](https://js.icp.build/auth/latest/).
## Contributing
Contributions are welcome! Please see the [contribution guide](./.github/CONTRIBUTING.md) for more information.
## License
This project is licensed under the [Apache-2.0](./LICENSE) license.