Hi,
I try to use auth0 for my react-native (expo) app.
After read the documentation, i find using the “Authorization Code Flow with PKCE” is most suitable.
So first, i create an Application “Machine to Machine” and setup the callback URL.
I also created an API an add my application to “Machine to Machine Applications”
- create an Application “Machine to Machine”
- setup the callback URL
- set “Token Endpoint Authentication Method” to "Post’
- created an API an add my application to “Machine to Machine Applications”
You can see the code for the first call :
let authUrl = `${auth0Domain}/authorize?` + this.toQueryString({
client_id: uth0ClientId,
response_type: 'code',
scope: 'openid profile email',
redirect_uri: redirectUrl,
code_challenge: challenge,
code_challenge_method: 'S256',
audience:`${auth0Domain}/api/v2/`
});
const result = await AuthSession.startAsync({
authUrl: authUrl
});
The first call is working properly, i get the Authorization code.
My problem is for getting the token :
var dataToken = new URLSearchParams();
dataToken.append('client_id', getEnvVars().auth0ClientId);
dataToken.append('grant_type', 'authorization_code');
dataToken.append('redirect_uri', redirectUrl);
dataToken.append('code_verifier', verifier);
dataToken.append('code', codeResult);
var options = {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: dataToken.toString()
};
fetch('https://dev-fo5rwjn9.eu.auth0.com/oauth/token', options).then(result => {
console.log(JSON.stringify(result, null, 2));
console.log(result.status);
}).catch(error => {
console.log(error);
});
Here i get an “error”: “access_denied”.
Do you know why i have this problem ? do i need to register my app as “native” ?
cordially,
Sylvain