-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client: allow to authenticate from existing refresh token
- Loading branch information
Showing
8 changed files
with
80 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@lens-protocol/client": patch | ||
--- | ||
|
||
**chore**: Relax node version requirements to >18 <21 |
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,5 @@ | ||
--- | ||
"@lens-protocol/client": minor | ||
--- | ||
|
||
**feat**: Added `authentication.fromRefreshToken` method to allow to authenticate LensClient from an existing refresh token |
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,21 @@ | ||
import { LensClient, development } from '@lens-protocol/client'; | ||
|
||
async function main() { | ||
const client = new LensClient({ | ||
environment: development, | ||
}); | ||
|
||
const token = 'YOUR_VALID_REFRESH_TOKEN_HERE'; | ||
await client.authentication.fromRefreshToken(token); | ||
|
||
console.log(`Is LensClient authenticated? `, await client.authentication.isAuthenticated()); | ||
|
||
const accessTokenResult = await client.authentication.getAccessToken(); | ||
const accessToken = accessTokenResult.unwrap(); | ||
const profileId = await client.authentication.getProfileId(); | ||
|
||
console.log(`Authenticated profileId: `, profileId); | ||
console.log(`Access token: `, accessToken); | ||
} | ||
|
||
main(); |
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,36 @@ | ||
import { LensClient, development } from '@lens-protocol/client'; | ||
|
||
import { setupWallet } from '../shared/setupWallet'; | ||
|
||
async function main() { | ||
const client = new LensClient({ | ||
environment: development, | ||
headers: { | ||
origin: 'https://lens-scripts.example', | ||
}, | ||
}); | ||
|
||
const wallet = setupWallet(); | ||
const address = await wallet.getAddress(); | ||
|
||
const managedProfiles = await client.wallet.profilesManaged({ for: wallet.address }); | ||
|
||
if (managedProfiles.items.length === 0) { | ||
throw new Error(`You don't manage any profiles, create one first`); | ||
} | ||
|
||
const { id, text } = await client.authentication.generateChallenge({ | ||
signedBy: address, | ||
for: managedProfiles.items[0].id, | ||
}); | ||
|
||
console.log(`Challenge: `, text); // Notice the origin URL in the challenge message | ||
|
||
const signature = await wallet.signMessage(text); | ||
|
||
await client.authentication.authenticate({ id, signature }); | ||
|
||
console.log(`Is LensClient authenticated? `, await client.authentication.isAuthenticated()); | ||
} | ||
|
||
main(); |
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