-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add prerequisites docs & add class based React example (#6)
* updaed code to include class version of example * podfile.lock update * initial develop environment setup * more initial set up * reworded * reworded * spelling mistakes * typo * use full package name * Update example/classVersion.js
- Loading branch information
1 parent
8c27fd5
commit db28bfa
Showing
20 changed files
with
297 additions
and
12 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
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,61 @@ | ||
# Initial Development Environment Setup | ||
|
||
## Instructions | ||
|
||
For the purpose of demonstration, suppose we created a fresh React Native project called `testAppleButton`. | ||
|
||
* Open your project in Xcode by clicking `open another project`, and navigating to this file: `testAppleButton/ios/testAppleButton.xcodeproj` | ||
|
||
 | ||
|
||
* Click `testAppleButton` under the target's header. | ||
|
||
 | ||
|
||
* Click `Signing and capabilities` to show the below noted view. Click `+ Capability` and from the menu select `Sign in with Apple` which will appear at the bottom as highlighted. | ||
|
||
 | ||
|
||
* You will need to sign in as a team if you have this error message. | ||
|
||
 | ||
|
||
* If successful, your status should show no error message like below. | ||
|
||
 | ||
|
||
* Head over to [Apple's developer console](https://developer.apple.com/). Click `Account` in the nav bar at the top. You will either have to sign in, or create an account. Your account dashboard ought to look like this. If you do not see `Certificates, IDs & profiles` as an option in the left-hand sidebar, it means you have not yet enrolled in the [Apple developer program](https://developer.apple.com/programs/) which is a prerequisite for Apple product development. | ||
|
||
 | ||
|
||
* Click on `Identifiers` in the left-hand sidebar. Click on your project in the list, in our case, `testAppleButton`. | ||
|
||
 | ||
|
||
* Tick the checkbox for `Sign in with Apple` and click the `Edit` button. Select `Enable as a primary App ID` and click `Save` button. | ||
|
||
 | ||
|
||
* Click the `Save` button at the top of the screen. | ||
|
||
 | ||
|
||
* Please note: If you choose another app to be your primary app, you will have to go through the above noted process, up until you navigate to the Apple developer console, and choose the `Group with existing primary App ID` option & the `testAppleButton` ID. | ||
|
||
 | ||
|
||
* Click on `keys` in left-hand sidebar and create a new key. | ||
|
||
 | ||
|
||
* Give your new key a name. Tick the checkbox next to `Sign In with Apple`, and click `Configure`. | ||
|
||
 | ||
|
||
* Select `testAppleButton` as our primary app ID. | ||
|
||
 | ||
|
||
* Register your key, download it and keep it secure. Initial setup is now complete. | ||
|
||
 |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,209 @@ | ||
/* eslint-disable no-console */ | ||
/* | ||
* Copyright (c) 2016-present Invertase Limited & Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this library except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import React from 'react'; | ||
import { AppRegistry, StyleSheet, View, Text } from 'react-native'; | ||
import auth, { | ||
AppleButton, | ||
AppleAuthError, | ||
AppleAuthRequestScope, | ||
AppleAuthRealUserStatus, | ||
AppleAuthCredentialState, | ||
AppleAuthRequestOperation, | ||
} from '@invertase/react-native-apple-authentication'; | ||
|
||
|
||
class Tester extends React.Component { | ||
constructor() { | ||
super(); | ||
this.authCredentialListener = null; | ||
this.user = null; | ||
this.state = { | ||
credentialStateForUser: -1, | ||
} | ||
} | ||
componentDidMount() { | ||
/** | ||
* subscribe to credential updates.This returns a function which can be used to remove the event listener | ||
* when the component unmounts. | ||
*/ | ||
this.authCredentialListener = auth.onCredentialRevoked(async () => { | ||
console.warn('Credential Revoked'); | ||
this.fetchAndUpdateCredentialState().catch(error => | ||
this.setState({ credentialStateForUser: `Error: ${error.code}` }), | ||
); | ||
}); | ||
|
||
this.fetchAndUpdateCredentialState() | ||
.then(res => this.setState({ credentialStateForUser: res })) | ||
.catch(error => this.setState({ credentialStateForUser: `Error: ${error.code}` })) | ||
} | ||
|
||
componentWillUnmount() { | ||
/** | ||
* cleans up event listener | ||
*/ | ||
this.authCredentialListener(); | ||
} | ||
|
||
signIn = async () => { | ||
console.warn('Beginning Apple Authentication'); | ||
|
||
// start a login request | ||
try { | ||
const appleAuthRequestResponse = await auth.performRequest({ | ||
requestedOperation: AppleAuthRequestOperation.LOGIN, | ||
requestedScopes: [ | ||
AppleAuthRequestScope.EMAIL, | ||
AppleAuthRequestScope.FULL_NAME, | ||
], | ||
}); | ||
|
||
console.log('appleAuthRequestResponse', appleAuthRequestResponse); | ||
|
||
const { | ||
user: newUser, | ||
email, | ||
nonce, | ||
identityToken, | ||
realUserStatus /* etc */, | ||
} = appleAuthRequestResponse; | ||
|
||
this.user = newUser; | ||
|
||
this.fetchAndUpdateCredentialState() | ||
.then(res => this.setState({ credentialStateForUser: res })) | ||
.catch(error => | ||
this.setState({ credentialStateForUser: `Error: ${error.code}` }), | ||
); | ||
|
||
if (identityToken) { | ||
// e.g. sign in with Firebase Auth using `nonce` & `identityToken` | ||
console.log(nonce, identityToken); | ||
} else { | ||
// no token - failed sign-in? | ||
} | ||
|
||
if (realUserStatus === AppleAuthRealUserStatus.LIKELY_REAL) { | ||
console.log("I'm a real person!"); | ||
} | ||
|
||
console.warn(`Apple Authentication Completed, ${this.user}, ${email}`); | ||
} catch (error) { | ||
if (error.code === AppleAuthError.CANCELED) { | ||
console.warn('User canceled Apple Sign in.'); | ||
} else { | ||
console.error(error); | ||
} | ||
} | ||
}; | ||
|
||
fetchAndUpdateCredentialState = async () => { | ||
if (this.user === null) { | ||
this.setState({ credentialStateForUser: 'N/A' }); | ||
} else { | ||
const credentialState = await auth.getCredentialStateForUser(this.user); | ||
if (credentialState === AppleAuthCredentialState.AUTHORIZED) { | ||
this.setState({ credentialStateForUser: 'AUTHORIZED' }); | ||
} else { | ||
this.setState({ credentialStateForUser: credentialState }); | ||
} | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<View style={[styles.container, styles.horizontal]}> | ||
<Text style={styles.header}>Credential State</Text> | ||
<Text>{this.state.credentialStateForUser}</Text> | ||
<Text style={styles.header}>Buttons</Text> | ||
<Text>Continue Styles</Text> | ||
<AppleButton | ||
style={styles.appleButton} | ||
cornerRadius={5} | ||
buttonStyle={AppleButton.Style.WHITE} | ||
buttonType={AppleButton.Type.CONTINUE} | ||
onPress={() => this.signIn()} | ||
/> | ||
<AppleButton | ||
style={styles.appleButton} | ||
cornerRadius={5} | ||
buttonStyle={AppleButton.Style.WHITE_OUTLINE} | ||
buttonType={AppleButton.Type.CONTINUE} | ||
onPress={() => this.signIn()} | ||
/> | ||
<AppleButton | ||
style={styles.appleButton} | ||
cornerRadius={5} | ||
buttonStyle={AppleButton.Style.BLACK} | ||
buttonType={AppleButton.Type.CONTINUE} | ||
onPress={() => this.signIn()} | ||
/> | ||
<Text>Sign-in Styles</Text> | ||
<AppleButton | ||
style={styles.appleButton} | ||
cornerRadius={5} | ||
buttonStyle={AppleButton.Style.WHITE} | ||
buttonType={AppleButton.Type.SIGN_IN} | ||
onPress={() => this.signIn()} | ||
/> | ||
<AppleButton | ||
style={styles.appleButton} | ||
cornerRadius={5} | ||
buttonStyle={AppleButton.Style.WHITE_OUTLINE} | ||
buttonType={AppleButton.Type.SIGN_IN} | ||
onPress={() => this.signIn()} | ||
/> | ||
<AppleButton | ||
style={styles.appleButton} | ||
cornerRadius={5} | ||
buttonStyle={AppleButton.Style.BLACK} | ||
buttonType={AppleButton.Type.SIGN_IN} | ||
onPress={() => this.signIn()} | ||
/> | ||
</View> | ||
) | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
appleButton: { | ||
width: 200, | ||
height: 60, | ||
margin: 10, | ||
}, | ||
header: { | ||
margin: 10, | ||
marginTop: 30, | ||
fontSize: 18, | ||
fontWeight: '600', | ||
}, | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
backgroundColor: 'pink', | ||
}, | ||
horizontal: { | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
padding: 10, | ||
}, | ||
}); | ||
|
||
AppRegistry.registerComponent('testing', () => Tester); |
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