i hope you have a great day!
I'm in the middle of learning Expo Auth using Azure
for sign-in to my app, at the moment, i think i have finished the configuration, and i already got the response
but the problem is:
i need to know, what email is user use for sign-in, and the response i got is like:
Response: Object {
"authentication": null,
"error": null,
"errorCode": null,
"params": Object {
"code": "0.AVUAOn_br_87QEeWJE1gRRLp8JZUWAsn4SlMrJ3ARoeW5xiIAAA.AgABAAIAAAD--DLA3VO7QrddgJg7WevrAgDs_wQA9P9Mz5y-YHO_5MJpyMzFGEX_1BO13SPiqBWHReXV06bRMS_YZoPG1GKYsput0mytF0FGtKiT2uD34fvkwvs98ZBtn2z5uQlHmKgaxMmkq5RjVAdzcg_glT1AsqgDFergWoi3FRJavMn8LiSizFhm9MlzhyaXChDN_OMyAu98zmtH4LaIjuGWVhxh5MgGz4QhRD9TIgxRi8npVrDBbpx68-AXVambsavXskwwLWerHDwLb2gufAsuP9O-DH1tY7knMQHrfQJqurl85RTSAtQq-FwKKTnC_4P7NRpmnG1htvmebFoGIXzWN9Wj38WsWMqin2rGYTys0yCV7hPy6YIBanRIR_0WUbyAkzR919l-_pf3o6B_iCkShq9YJPivOWh-ukCjWbApr9pD__UEt0QpQtQNra92GJjE_m7tLpzl-DlvW1bT77Gc9tvlhsh3rU8N-m69WFavYDffxq8WnuESm2eDSTJM6d6pAOWlApcvaeg_dwA14h88gF_yiUw7wq3uREVmmJo9A8TK7gBFJ7JvFZcizMzCrnBpdI8Cw34ya7HJGqthPqhR4W3fz2anF-gUxCzjBuvuevxrxUMX7VpGw9MPga9v7YEjI61V70ILemePB1fbWZ82natxh-2qAzj0mhdtO5JLLpr-nOovKnM4qZUhksPNup317z4jsVUALK_6Z13dzjPgN9V69HwNSlWiYP7vyvF7Tl61rt-8XIhxqRUdf_Mn6wIvkuDEsFYucYZNyNu8oJ4We81YEIhguqs08t3fdZxiunO7M_hRrsIMhCbRSDxx2l18a3XTgDreepEDhwJES_xxxxxLvSv3u8djryTMY-TwLpF7cejtheQIZbJe3hXXs3SKLQMkS-JxjbiFjrDias45uWubOpuQ1kaHSutq7wa05wdGSYw0OPGguQux0UNwnRAsrNDDD6f57oko1932s28M11GVsUBDOaePoQF3KFtZ90n-rbdxFRHbVli2fDNxQOJPO8qDdSVb_uPuK0609jmP6TxFmbtTWwsvKerZilbiZPdEti45mSsyj9h_ysxd5Mx-Dhwj-5Tang5KxI0ggbiqV0RF4zPsxAuxxxxxbgubh3rdtLQujVDFNf8HJa1k70cNqPYe0Fe0hpfVxjfKqgWcSEqI8MdFfCJXRXdD8ixzd7LKT-X1vlFdr3FZqn939lY",
"session_state": "ea378174-d80c-4811-bc1f-adc6b732b863",
"state": "9xrNttNeAf",
},
"type": "success",
"url": "myapp://login/?code=0.AVUAOn_br_87QEeWJE1gRRLp8JZUWAsn4SlMrJ3ARoeW5xiIAAA.AgABAAIAAAD--DLA3VO7QrddgJg7WevrAgDs_wQA9P9Mz5y-YHO_5MJpyMzFGEX_1BO13SPiqBWHReXV06bRMS_YZoPG1GKYsput0mytF0FGtKiT2uD34fvkwvs98ZBtn2z5uQlHmKgaxMmkq5RjVAdzcg_glT1AsqgDFergWoi3FRJavMn8LiSizFhm9MlzhyaXChDN_OMyAu98zmtH4LaIjuGWVhxh5MgGz4QhRD9TIgxRi8npVrDBbpx68-AXVambsavXskwwLWerHDwLb2gufAsuP9O-DH1tY7knMQHrfQJqurl85RTSAtQq-FwKKTnC_4P7NRpmnG1htvmebFoGIXzWN9Wj38WsWMqin2rGYTys0yCV7hPy6YIBanRIR_0WUbyAkzR919l-_pf3o6B_iCkxxxxxvOWh-ukCjWbApr9pD__UEt0QpQtQNra92GJjE_m7tLpzl-DlvW1bT77Gc9tvlhsh3rU8N-m69WFavYDffxq8WnuESm2eDSTJM6d6pAOWlApcvaeg_dwA14h88gF_yiUw7wq3uREVmmJo9A8TK7gBFJ7JvFZcizMzCrnBpdI8Cw34ya7HJGqthPqhR4W3fz2anF-gUxCzjBuvuevxrxUMX7VpGw9MPga9v7YEjI61V70ILemePB1fbWZ82natxh-2qAzj0mhdtO5JLLpr-nOovKnM4qZUhksPNup317z4jsVUALK_6Z13dzjPgN9V69HwNSlWiYP7vyvF7Tl61rt-8XIhxqRUdf_Mn6wIvkuDEsFYucYZNyNu8oJ4We81YEIhguqs08t3fdZxiunO7M_hRrsIMhCbRSDxx2l18a3XTgDreepEDhwJES_Da20GVhLvSv3u8djryTMY-TwLpF7cejtheQIZbJe3hXXs3SKLQMkS-JxjbiFjrDias45uWubOpuQ1kaHSutq7wa05wdGSYw0OPGguQux0UNwnRAsrNDDD6f57oko1932s28M11GVsUBDOaePoQF3KFtZ90n-rbdxFRHbVli2fDNxQOJPO8qDdSVb_uPuK0609jmP6TxFmbtTWwsvKerZilbiZPdEti45mSsyj9h_ysxd5Mx-Dhwj-5Tang5KxI0ggbiqV0RF4zPsxAucumAOpEJwjxbgubh3rdtLQujVDFNf8HJa1k70cNqPYe0Fe0hpfVxjfKqgWcSEqI8MdxxxxXRXdD8ixzd7LKT-X1vlFdr3FZqn939lY&state=9xrNttNeAf&session_state=ea378174-d80c-4811-bc1f-adc6b732b863",
}
and this is my code
const discovery = useAutoDiscovery(
"https://login.microsoftonline.com/xxxx/v2.0"
);
// Request
const [request, response, promptAsync] = useAuthRequest(
{
warmAndPrefetchChrome: true,
clientId: "xxxx",
scopes: ["Mail.read", "user.Read"],
additionalParameters: { prompt: "select_account" },
redirectUri: "myapp://login",
serviceConfiguration: {
authorizationEndpoint:
"https://login.microsoftonline.com/xxxx/oauth2/v2.0/authorize",
tokenEndpoint:
"https://login.microsoftonline.com/xxxx/oauth2/v2.0/token",
},
},
discovery
);
useEffect(() => {
if (response) {
console.log("Response: ", response);
console.log("Request: ", request);
}
}, [response]);
=========================== EDIT ===============================
i already try to get AccessTokenRequest and exchangeCodeAsync, looks like this:
useEffect(() => {
if (response && "params" in response) {
try {
const accessToken = new AuthSession.AccessTokenRequest({
code: response.params.code,
clientId: "xxxx",
redirectUri: "myapp://login",
scopes: ["openid", "profile", "email", "offline_access"],
extraParams: {
code_verifier: request?.codeVerifier ? request.codeVerifier : "",
},
});
console.log("------- Access ----------------");
console.log(accessToken);
console.log("-----------------------");
const responseToken = AuthSession.exchangeCodeAsync(accessToken, {
tokenEndpoint:
"https://login.microsoftonline.com/xxxx/oauth2/v2.0/token",
});
console.log(JSON.stringify(responseToken, null, 4));
} catch (error: any) {
console.log("Err: " error);
}
// console.log(response.params.code);
}
}, [response]);
Here's the log in accessToken
// console.log(accessToken)
AccessTokenRequest {
"clientId": "0b585496-e127-xxxx-xxxx-c0468796e718",
"clientSecret": undefined,
"code": "0.AVUAOn_br_87QEeWJE1gRRLp8JZUWAsn4SlMrJ3ARoeW5xiIAAA.AgABAAIAAAD--DLA3VO7QrddgJg7WevrAgDs_wQA9P-4Q4towRJ6ni2ygY4-CP3z0OyckxxSzunXKiX--nkhRKwnNHvbMvHKbgyUCFpeN_AaQi1xMZYZJMonH22e7tiqAU6zLk3PWpNDtyTGuQGB-CRBZkLLk-keOUdrWZRCI9k-8c5QDlCzfS6T1keoaFz9QKkmnX225PPOg-RQnhRxEVomG_9yj25ywnwEbr0pt8kUap0sAE8Tdj3LIzilgY-62cHkZWqjchUvBug_5QfY6i8L8y7PXfsFUaKNxvfCTB4kTFXZc-nC1LtirGsAqZSj1WWQXHejZNB368SNzYClKO65y_t9wZFz7r7gtMDBAaoABp9No1zfuHPUXiS1cEXlWpCsha5vjG8B20xxxxx7vdWNT88CYw5dWvELDPq0QRxJ8uqSrPTLJ9KPA32wwjrTFuWVuW7_oWhrl02tIImRDYsdkWUfM1xgVzahY22hi6gi7wkwmepR6ofoMOiFH29WAoOljHCD22ER3IB_Krt7Kxikkunn0gXx9V0055bqr29nRrl-kQuyMxCqBgYcoWATj8_C5bPiyG07GY1P3Xwi1QtesS8_H0N0rQjCqdM62ks6g6n-WD8Z0HLf7lec8DgbDDf82tJs2JIn9Xjpa2KqJ4Rw3m7KhLJIcYp81gGB5xfYiSnvSKhT6ibSrrbOOe467pOcSIsCC600XqcXea-wfBeBczJLR4es0EEDpjPEwJB4cOa1sDV1bAVzKjTizY7fiGCr-pWyQT4Jig66sqVPaMP2LFqKbSigOICOunihySdVX297uaocbCVWYU2oubkBqQYT-adWeo2I1X4TqkXmGGD0s50og1oNfuJjEvJaxhpaPPR2FO-Hv1Bj-GqUMylAWVG95Fs9HpC4VIv5ceib3NVEgMIivKtLc-JVY4stLcua8hdUn3GsZMjxZBb6dvZuSzI08DwzDl0NrV0PuJzhzEt8S3HhE9xesQlbS2X4G-asyMJUDtTR1286SFFzwalkyt18rwaLbh08nfBJDfxH_3PE5ojhmeGbfa6tvzXr-V1u4EG0uAa-OHsesseVuGfKdUtM6uc3ZxlCF77SU-ZLJhFKP1D3zQ7SIp3JShuobw7PShTt8YVfWlZD2psG67RP1ht-JNwXzCtKe4SoUl_Loi5jZeojcsQt3c1rXdd7BR7k4niRn3x56x6EYP3kgf4abQUi7AmFLkXl369fD3uNGosWxXfv-A3uJyV6zr5sqWtBOy6ONwsA_fSa4cHQ5M",
"extraParams": Object {
"code_verifier": "T2VLnxBT7HWyZMAxuiwAWHrcuywNmhGf6GxxxxEJU8iPSnkqAXx6dfaLutGnczQmD4jOjQEp47CG9PlipEaXHJZqJDBAGGOTl5RR6AUlMzB7Yi1bSiGjhq3iOyd8",
},
"grantType": "authorization_code",
"redirectUri": "binusfma://login",
"request": Object {
"clientId": "0b585496-e127-4c29-ac9d-c0468796e718",
"code": "0.AVUAOn_br_87QEeWJE1gRRLp8JZUWAsn4SlMrJ3ARoeW5xiIAAA.AgABAAIAAAD--DLA3VO7QrddgJg7WevrAgDs_wQA9P-4Q4towRJ6ni2ygY4-CP3z0OyckxxSzunXKiX--nkhRKwnNHvbMvHKbgyUCFpeN_AaQi1xMZYZJMonH22e7tiqAU6zLk3PWpNDtyTGuQGB-CRBZkLLk-keOUdrWZRCI9k-8c5QDlCzfS6T1keoaFz9QKkmnX225PPOg-RQnhRxEVomG_9yj25ywnwEbr0pt8kUap0sAE8Tdj3LIzilgY-62cHk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utGnczQmD4jOjQEp47CG9PlipEaXHJZqJDBAGGOTl5RR6AUlMzB7Yi1bSiGjhq3iOyd8",
},
"redirectUri": "binusfma://login",
"scopes": Array [
"openid",
"profile",
"email",
"offline_access",
],
},
"scopes": Array [
"openid",
"profile",
"email",
"offline_access",
],
}
and this is what i get with responseToken
{
"_U": 0,
"_V": 0,
"_W": null,
"_X": null
}
in the terminal, i got warning like:
AADSTS501481: The Code_Verifier does not match the code_challenge supplied in the authorization request
and i still get no email or username
can you help me? please :(
CodePudding user response:
AuthSession.exchangeCodeAsync is a promise, you can do this:
AuthSession.exchangeCodeAsync(accessToken, {
tokenEndpoint:
'https://login.microsoftonline.com/xxxx/oauth2/v2.0/token',
})
.then((res) => {
console.log('------- Response Token ----------------');
console.log('res ', res);
})
.catch((err) => console.log(err));
I was able to query here in postman with the accessToken I got there. https://graph.microsoft.com/v1.0/me