Skip to content

Instantly share code, notes, and snippets.

@mebinum
Last active November 21, 2016 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mebinum/7aa047d23919299231c52ebfb7d528dd to your computer and use it in GitHub Desktop.
Save mebinum/7aa047d23919299231c52ebfb7d528dd to your computer and use it in GitHub Desktop.
//import the component into your project
import {AzureInstance, AzureLoginView} from 'react-native-azure-ad-2'
//create an AzureInstance object with your Microsoft Azure credentials
var credentials = {
client_id: 'xxxxxxxx',
client_secret: 'xxxxxx',
scope: 'User.ReadBasic.All Mail.Read offline_access' //access scope for login - see http://bit.ly/2gtQe9W for more info
};
//create a component for Azure Authentication
export default class azureAuth extends React.Component {
constructor(props){
super(props);
//instantiate azure objects with your azure credentials
this.azureInstance = new AzureInstance(credentials);
//bind the login success function
this._onLoginSuccess = this._onLoginSuccess.bind(this);
}
// function to be called after login is successful
_onLoginSuccess(){
this.azureInstance.getUserInfo().then(result => {
console.log(result);
}).catch(err => {
console.log(err);
})
}
// pass the azureInstance and Login Success function to the AzureLoginView that will display
// the authentication screen
render() {
return (
<AzureLoginView
azureInstance={this.azureInstance}
loadingMessage="Requesting access token"
onSuccess={this._onLoginSuccess}
/>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment