console.error: "ERROR:", "ADLoginView._getResourceAccessToken", {}
ERROR: ADLoginView._getResourceAccessToken Error: Failed to acquire token for resources
React native app code as below
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
StyleSheet,
Text,
Button,
View
} from 'react-native';
import {ReactNativeAD, ADLoginView, Logger} from 'react-native-azure-ad';
const CLIENT_ID = '6dcb8e63-5482-45a9-8c30-c701b25c9834';
export default class App extends Component {
constructor(props) {
super(props)
this.AzureADContext = {
client_id : CLIENT_ID,
resources : [
'https://graph.microsoft.com',
'https://outlook.office.com',
'https://outlook.office365.com',
'https://wiadvancetechnology.sharepoint.com',
'https://graph.windows.net',
]
}
this.state = {};
}
render() {
new ReactNativeAD({
client_id: CLIENT_ID,
resources: [
'https://graph.microsoft.com',
'https://outlook.office.com',
'https://outlook.office365.com',
'https://wiadvancetechnology.sharepoint.com',
'https://graph.windows.net',
]
})
return <ADLoginView
context={ReactNativeAD.getContext(CLIENT_ID)}
onSuccess={this.onLoginSuccess.bind(this)}/>
}
onLoginSuccess(credentials) {
console.log(credentials['https://outlook.office365.com'].access_token)
// use the access token ..
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 20,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
Any idea?
Package.json
{
"name": "LoginTest",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.2.0",
"react-native": "0.53.3",
"react-native-azure-ad": "^0.2.4"
},
"devDependencies": {
"babel-jest": "22.4.1",
"babel-preset-react-native": "4.0.0",
"jest": "22.4.2",
"react-test-renderer": "16.2.0"
},
"jest": {
"preset": "react-native"
}
}
Same problem. Looks like that the library is unmaintained
This is most likely not an issue with library, but rather with your azure app registration.
please verify those two potential fixes:
-
create special URL that needs to be hit by tenant administrator: https://login.microsoftonline.com/<tenant_name_in_onmicrosoft.com-form>/oauth2/authorize?client_id=<appId>&response_type=code&redirect_uri=http://<appUri>&nonce=1234&resource=https://graph.windows.net&prompt=admin_consent
-
make sure that your native application has got API you try to call in required permissions. This is most likely caused by this app:
'https://wiadvancetechnology.sharepoint.com',in your resources
Same problem. I used the exact same code as https://github.com/wkh237/rn-azure-ad-sample/blob/master/index.common.js
Any idea?
In constructor the resources option is the issue. Please try to mention graph api url both in constructor and your render method.
Also configure graph api properly on azure portal. You can check Microsoft official document to configure your graph api on azure portal
It worked for me
I got this error when my onSuccess method did not have a this binding. Converting it into an arrow function solved the issue.
I had the same issue and found the problem in authority url. FYI, I was using react-native.
Change the authority from
authority: 'https://login.microsoftonline.com/common/v2.0' -> authority: 'https://login.windows.net/common'
and rest of the fields are as follows:
resourceId: 'https://graph.windows.net/',
clientId: '3333387f-2XX3-4XXX-bXXX-0ce3e079XXX',
iosRedirectUri: 'x-msauth-org-reactjs-native-example-sample://org.reactjs.native.example.sample',
androidRedirectUri: 'msal3333387f-2XX3-4XXX-bXXX-0ce3e079XXX://auth',
brokeredAuth: false