react-native-sp-auth
v1.1.3
Published
React Native SharePoint Online Authentication
Readme
react-native-sp-auth
Getting started
$ yarn add react-native-sp-auth
Mostly automatic installation
$ react-native link react-native-sp-auth
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries➜Add Files to [your project's name] - Go to
node_modules➜react-native-sp-authand addRNSpAuth.xcodeproj - In XCode, in the project navigator, select your project. Add
libRNSpAuth.ato your project'sBuild Phases➜Link Binary With Libraries - Run your project (
Cmd+R)<
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.fx.rnspauth.RNSpAuthPackage;to the imports at the top of the file - Add
new RNSpAuthPackage()to the list returned by thegetPackages()method
- Append the following lines to
android/settings.gradle:include ':react-native-sp-auth' project(':react-native-sp-auth').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sp-auth/android') - Insert the following lines inside the dependencies block in
android/app/build.gradle:compile project(':react-native-sp-auth')
Usage
import RNSharePointAuth from 'react-native-sp-auth';
const sp = new RNSharePointAuth('https://yoursite.sharepoint.com');
try {
// trying to restore session
const digest = await sp.renewDigest();
} catch (e) {
// can't automatic restore the session, read token from Storage
const token = await Storage.getItem('token');
if (token) {
await sp.setToken(token);
try {
const digest = await sp.renewDigest();
} catch (e1) {
// can't restore the session, re-login
const { digest, token } = await sp.login('yourusername@yourdomain', 'yourpassword');
// store token back to Storage
await Storage.setItem('token', token);
}
}
}
// renew digest if expired
const newDigest = await sp.renewDigest();
// obtain digest for site collection
const digest4SiteCollection = await sp.renewDigest('/sites/o40');