Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 537a80b

Browse files
committed
implement remove refresh token
1 parent 3d35265 commit 537a80b

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed

android/src/main/java/com/reactnativecryptr/CryptrModule.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ class CryptrModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
104104
}
105105
}
106106

107+
@ReactMethod(isBlockingSynchronousMethod = true)
108+
fun removeRefresh(successCallback: Callback, errorCallback: Callback) {
109+
val editor: SharedPreferences.Editor = this.sharedPreferences.edit();
110+
editor.remove(REFRESH_TOKEN_KEY);
111+
if(editor.commit()) {
112+
successCallback.invoke("Refresh removed");
113+
} else {
114+
errorCallback.invoke("Error while removing refresh");
115+
}
116+
}
117+
107118
@ReactMethod(isBlockingSynchronousMethod = true)
108119
fun startSecuredView(
109120
uri: String,

ios/Cryptr.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ - (void)openInSafari:(NSURL *)URL {
6262
}
6363
}
6464

65+
RCT_EXPORT_METHOD(removeRefresh:(RCTResponseSenderBlock)callback
66+
errorCallback:(RCTResponseSenderBlock)errorCallback)
67+
{
68+
NSDictionary* removeQuery = @{
69+
(__bridge id)kSecClass : (__bridge id)kSecClassGenericPassword,
70+
(__bridge id)kSecAttrAccount : REFRESH_TOKEN_KEY,
71+
(__bridge id)kSecReturnData : (__bridge id)kCFBooleanTrue
72+
};
73+
74+
OSStatus removeStatus = SecItemDelete((__bridge CFDictionaryRef)removeQuery);
75+
76+
if (removeStatus == noErr) {
77+
callback(@[@"Refresh removed"]);
78+
}
79+
80+
else {
81+
NSError* error = [NSError errorWithDomain:[[NSBundle mainBundle] bundleIdentifier] code:removeStatus userInfo: nil];
82+
errorCallback(@[@"An error occured while removing value"]);
83+
}
84+
}
85+
6586
RCT_EXPORT_METHOD(getRefresh:(RCTResponseSenderBlock)callback
6687
errorCallback:(RCTResponseSenderBlock)errorCallback)
6788
{

src/models/Cryptr.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ interface CryptrInterface {
1616
successCallback?: (data: any) => any,
1717
errorCallback?: (error: any) => any
1818
) => any;
19+
removeRefresh: (
20+
successCallback?: (data: any) => any,
21+
errorCallback?: (error: any) => any
22+
) => any;
1923
setRefresh: (
2024
refreshToken: string,
2125
successCallback?: (data: any) => any,

src/models/CryptrProvider.tsx

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,26 +164,33 @@ const CryptrProvider: React.FC<ProviderProps> = ({
164164
const { revoked_at, slo_code } = json;
165165
if (revoked_at) {
166166
setUnAuthenticated();
167-
if (slo_code) {
168-
let sloUrl = sloAfterRevokeTokenUrl(config, slo_code);
169-
if (Platform.OS === 'android') {
170-
Cryptr.startSecuredView(
171-
sloUrl,
172-
(_data: any) => {
173-
callback && callback(json);
174-
},
175-
(error: any) => {
176-
setError(error);
177-
errorCallback && errorCallback(error);
167+
Cryptr.removeRefresh(
168+
(_data: any) => {
169+
if (slo_code) {
170+
let sloUrl = sloAfterRevokeTokenUrl(config, slo_code);
171+
if (Platform.OS === 'android') {
172+
Cryptr.startSecuredView(
173+
sloUrl,
174+
(_d: any) => {
175+
callback && callback(json);
176+
},
177+
(error: any) => {
178+
setError(error);
179+
errorCallback && errorCallback(error);
180+
}
181+
);
178182
}
179-
);
183+
} else {
184+
if (callback) callback(json);
185+
}
186+
},
187+
(error: any) => {
188+
errorCallback && errorCallback(error);
180189
}
181-
} else {
182-
if (callback) callback(json);
183-
}
190+
);
184191
} else {
185192
setUnloading();
186-
if (callback) callback(json);
193+
if (errorCallback) errorCallback(json);
187194
}
188195
};
189196

@@ -259,7 +266,11 @@ const CryptrProvider: React.FC<ProviderProps> = ({
259266
}
260267
},
261268
(error: any) => {
262-
setError(error);
269+
dispatch({
270+
type: CryptrReducerActionKind.UNAUTHENTICATED,
271+
payload: { error: error },
272+
});
273+
errorCallback && errorCallback(error);
263274
}
264275
);
265276
};

0 commit comments

Comments
 (0)