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

console.error: "ERROR:", "ADLoginView._getResourceAccessToken", {} #32

Open
AnthonyNTK opened this issue Feb 23, 2018 · 6 comments
Open

Comments

@AnthonyNTK
Copy link

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"
  }
}

@baltuonis
Copy link

Same problem. Looks like that the library is unmaintained

@general-albatross
Copy link

This is most likely not an issue with library, but rather with your azure app registration.

please verify those two potential fixes:

  1. 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=&response_type=code&redirect_uri=http://&nonce=1234&resource=https://graph.windows.net&prompt=admin_consent

  2. 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

@glautrou
Copy link

Same problem.
I used the exact same code as https://github.com/wkh237/rn-azure-ad-sample/blob/master/index.common.js

Any idea?

@divyamakkar26
Copy link

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

@glocore
Copy link

glocore commented Jan 9, 2019

I got this error when my onSuccess method did not have a this binding. Converting it into an arrow function solved the issue.

@raj4all
Copy link

raj4all commented Mar 19, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants