vmurin / react-native-azure-auth

React Native library implementing Azure AD OAuth2 API
MIT License
85 stars 64 forks source link

Returned id_token could not be decoded #218

Closed Harmew closed 1 month ago

Harmew commented 1 month ago

When i login

image

i received this error

ERROR: The returned id_token could not be decoded [Error: Not a valid base64 encoded string length] LOG Error during Azure operation [TypeError: Cannot read property 'preferred_username' of null]

somebody can help me? or this is because the lib use @react-native-async-storage/async-storage@^1.23.1?

Harmew commented 1 month ago

i installed version @react-native-async-storage/async-storage@1.13.0 and not work

Harmew commented 1 month ago

i found the error in /src/token/token.js

in this function

import { Base64 } from 'js-base64'

function base64DecodeStringUrlSafe(base64IdToken) { return decodeURIComponent(Base64.decode(base64IdToken)) }

i dont know why this Base64 cant decode the string, with i test in browser decode https://www.base64decode.org/

the same string works????

VeljkoSkrbic commented 1 month ago

Hi, @Harmew I had the same problem, I went to react-native-azure-auth/src/token/token.js and found that the problem is in the library itself so I just changed it to the 'jwt-decode' instead of 'js-base64' and it works now.

import {jwtDecode} from 'jwt-decode'

export function extractIdToken(encodedIdToken) {

    const decodedToken = jwtDecode(encodedIdToken)
    console.log('decodedToken', decodedToken)
    if (!decodedToken) {
        return null
    }

    return decodedToken;
}

also, the library does everything for us, so I removed the remaining code

vmurin commented 1 month ago

@VeljkoSkrbic thanks for your hint. Library updated.

QendresaB-OM commented 1 month ago

I'm still receiving erors even after updating, I see that the library 'js-base64' is also being used in the baseTokenItem.js file, does this also require some changed with the other library 'jwt-decode'? @vmurin

vmurin commented 1 month ago

I'm still receiving erors even after updating, I see that the library 'js-base64' is also being used in the baseTokenItem.js file, does this also require some changed with the other library 'jwt-decode'? @vmurin

Please post here a full stack trace of your error. Or some another info, that could help to analyse the issue.

QendresaB-OM commented 1 month ago
image

I noticed it works on some cases, but maybe after the tokens are saved in the cache and received from it, there might be the issue @vmurin

vmurin commented 1 month ago

@QendresaB-OM Please look at the screenshot above in this issue - in the stack trace there we can see the source files and code line numbers, so we could analyse the cause. Do you have the same from your issues?