diff --git a/packages/atproto_oauth/lib/src/oauth_client.dart b/packages/atproto_oauth/lib/src/oauth_client.dart index 97426b6bd..27abab9f3 100644 --- a/packages/atproto_oauth/lib/src/oauth_client.dart +++ b/packages/atproto_oauth/lib/src/oauth_client.dart @@ -357,8 +357,7 @@ final class OAuthClient { final body = jsonDecode(response.body); - if (response.statusCode == 401 && - body['error'] == 'use_dpop_nonce' && + if (body['error'] == 'use_dpop_nonce' && response.headers.containsKey('dpop-nonce')) { session.$dPoPNonce = response.headers['dpop-nonce']!; diff --git a/packages/bluesky/example/example.dart b/packages/bluesky/example/example.dart index dbbadebe4..c40d946c5 100644 --- a/packages/bluesky/example/example.dart +++ b/packages/bluesky/example/example.dart @@ -4,6 +4,7 @@ import 'dart:io'; +import 'package:atproto_core/atproto_core.dart'; import 'package:atproto_core/atproto_oauth.dart'; import 'package:bluesky/app_bsky_embed_video.dart'; import 'package:bluesky/atproto.dart'; @@ -180,8 +181,16 @@ Future get _oAuthSession async { print(session.$publicKey); print(session.$privateKey); + // You can restore OAuthSession from stored keys + final restoredSession = restoreOAuthSession( + accessToken: session.accessToken, + refreshToken: session.refreshToken, + publicKey: session.$publicKey, + privateKey: session.$privateKey, + ); + // If you want to refresh session // final refreshed = await oauth.refresh(bsky.oAuthSession!); - return session; + return restoredSession; }