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

Update v4 upstream #1022

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-auth0",
"name": "@speechmatics/react-native-auth0",
"title": "React Native Auth0",
"version": "4.0.0",
"version": "4.0.1-sm.0",
"description": "React Native toolkit for Auth0 API",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
15 changes: 15 additions & 0 deletions src/hooks/auth0-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
WebAuthorizeParameters,
PasswordlessWithSMSOptions,
ClearSessionOptions,
ExchangeNativeSocialOptions,
RevokeOptions,
} from '../types';

export interface Auth0ContextInterface<TUser extends User = User>
Expand Down Expand Up @@ -71,6 +73,13 @@ export interface Auth0ContextInterface<TUser extends User = User>
authorizeWithRecoveryCode: (
parameters: LoginWithRecoveryCodeOptions
) => Promise<Credentials | undefined>;
/**
* Exchange an external token obtained via a native social authentication solution for the user's tokens.
* See {@link Auth#exchangeNativeSocial}
*/
exchangeNativeSocial: (
parameters: ExchangeNativeSocialOptions
) => Promise<Credentials | undefined>;
/**
* Whether the SDK currently holds valid, unexpired credentials.
* @param minTtl The minimum time in seconds that the access token should last before expiration
Expand Down Expand Up @@ -105,6 +114,10 @@ export interface Auth0ContextInterface<TUser extends User = User>
* Clears the user's credentials without clearing their web session and logs them out.
*/
clearCredentials: () => Promise<void>;
/**
*Revokes an issued refresh token. See {@link Auth#revoke}
*/
revoke: (parameters: RevokeOptions) => Promise<void>;
}

export interface AuthState<TUser extends User = User> {
Expand Down Expand Up @@ -139,10 +152,12 @@ const initialContext = {
authorizeWithOOB: stub,
authorizeWithOTP: stub,
authorizeWithRecoveryCode: stub,
exchangeNativeSocial: stub,
hasValidCredentials: stub,
clearSession: stub,
getCredentials: stub,
clearCredentials: stub,
revoke: stub,
};

const Auth0Context = createContext<Auth0ContextInterface>(initialContext);
Expand Down
65 changes: 65 additions & 0 deletions src/hooks/auth0-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ClearSessionOptions,
ClearSessionParameters,
Credentials,
ExchangeNativeSocialOptions,
LoginWithEmailOptions,
LoginWithOOBOptions,
LoginWithOTPOptions,
Expand All @@ -22,6 +23,7 @@ import {
MultifactorChallengeOptions,
PasswordlessWithEmailOptions,
PasswordlessWithSMSOptions,
RevokeOptions,
User,
WebAuthorizeOptions,
WebAuthorizeParameters,
Expand Down Expand Up @@ -301,6 +303,23 @@ const Auth0Provider = ({
[client]
);

const exchangeNativeSocial = useCallback(
async (parameters: ExchangeNativeSocialOptions) => {
try {
const credentials = await client.auth.exchangeNativeSocial(parameters);
const user = getIdTokenProfileClaims(credentials.idToken);

await client.credentialsManager.saveCredentials(credentials);
dispatch({ type: 'LOGIN_COMPLETE', user });
return credentials;
} catch (error) {
dispatch({ type: 'ERROR', error });
return;
}
},
[client]
);

const hasValidCredentials = useCallback(
async (minTtl: number = 0) => {
return await client.credentialsManager.hasValidCredentials(minTtl);
Expand All @@ -318,6 +337,40 @@ const Auth0Provider = ({
}
}, [client]);

<<<<<<< HEAD
=======
const requireLocalAuthentication = useCallback(
async (
title?: string,
description?: string,
cancelTitle?: string,
fallbackTitle?: string,
strategy = LocalAuthenticationStrategy.deviceOwnerWithBiometrics
) => {
try {
await client.credentialsManager.requireLocalAuthentication(
title,
description,
cancelTitle,
fallbackTitle,
strategy
);
} catch (error) {
dispatch({ type: 'ERROR', error });
return;
}
},
[client.credentialsManager]
);

const revoke = useCallback(
(parameters: RevokeOptions) => {
return client.auth.revoke(parameters);
},
[client]
);

>>>>>>> b6515de (Add revoke function to top level hook)
const contextValue = useMemo(
() => ({
...state,
Expand All @@ -330,10 +383,16 @@ const Auth0Provider = ({
authorizeWithOOB,
authorizeWithOTP,
authorizeWithRecoveryCode,
exchangeNativeSocial,
hasValidCredentials,
clearSession,
getCredentials,
clearCredentials,
<<<<<<< HEAD
=======
requireLocalAuthentication,
revoke,
>>>>>>> b6515de (Add revoke function to top level hook)
}),
[
state,
Expand All @@ -346,10 +405,16 @@ const Auth0Provider = ({
authorizeWithOOB,
authorizeWithOTP,
authorizeWithRecoveryCode,
exchangeNativeSocial,
hasValidCredentials,
clearSession,
getCredentials,
clearCredentials,
<<<<<<< HEAD
=======
requireLocalAuthentication,
revoke,
>>>>>>> b6515de (Add revoke function to top level hook)
]
);

Expand Down