Error with code.ui required error: failed to get access token cache silently, please login first: you need login first before get access token. IOS Device #11602
Labels
investigating
needs more info
Need user to provide more info
no recent activity
The issue labeled needs more info gets no reply from issue owner in time
TA:Auth
Team Area: Auth
Describe the bug
I receive an error message when I try to connect with the Graph API to get the user profile.
The error message I receive is:
"Error with code.ui required error: failed to get access token cache silently, please login first: you need login first before getting access token on iOS mobile devices."
The Teams application works perfectly on Android.
Here is the code I use for authentication. Could you please tell me how to fix this bug?
export async function GetGraphEntity(options : string[], api : string, query : string, filter : string) {
const { scope } = { scope : ["User.Read"], ...options } ;
const credential : TeamsFx = new TeamsFx(IdentityType.User, {
initiateLoginEndpoint : process.env.REACT_APP_START_LOGIN_PAGE_URL !,
clientId : process.env.REACT_APP_CLIENT_ID !
}) ;
try {
credential.setSsoToken((await credential.getCredential().getToken(["User.Read Calendars.ReadWrite Contacts.Read MailboxSettings.ReadWrite"])) !.token ) ;
} catch (err : unknown) {
if (err instanceof ErrorWithCode && err.code ?.includes(ErrorCode.UiRequiredError)) {
await credential.login([
"User.Read Calendars.ReadWrite Contacts.Read MailboxSettings.ReadWrite",
]) ;
await credential.getCredential() ;
}
}
const graph = createMicrosoftGraphClient(credential, [
"User.Read Calendars.ReadWrite Contacts.Read MailboxSettings.ReadWrite",
]) ;
const profile = await graph.api("/me").get() ;
console.log("profile", profile)
}
"dependencies": {
"@azure/msal-browser": "^2.22.1",
"@azure/msal-react": "^1.3.1",
"@fluentui/react": "^8.63.1",
"@fluentui/react-northstar": "^0.66.3",
"@microsoft/microsoft-graph-client": "^3.0.5",
"@microsoft/teams-js": "^2.13.0",
"@microsoft/teamsfx": "^2.2.1",
"@microsoft/teamsfx-react": "^3.0.0",
"@types/microsoft-graph": "latest",
"msteams-react-base-component": "^3.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "5.1.2",
"react-scripts": "^5.0.1",
}
Script for auth-start.html and auth-end.html
<script src="https://res.cdn.office.net/teams-js/2.0.0/js/MicrosoftTeams.min.js" integrity="sha384-QtTBFeFlfRDZBfwHJHYQp7MdLJ2C3sfAEB1Qpy+YblvjavBye+q87TELpTnvlXw4" crossorigin="anonymous"></script>To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
VS Code Extension Information (please complete the following information):
CLI Information (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: