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a,OAAO,SAC1B,GAIJ,SAAS,EAAa,OAAO,KAAM,GAOrC,CACL,MAAS,qCACN,KAIZ,OAAO,IACN,QAAQ,MAAM,GACP,CACH,MAAU,EACV,KAAQ,WAKK,SAGd","file":"/npm/fgasulay-azure-ad-graph-expo@2.2.1/AzureADGraph.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/fgasulay-azure-ad-graph-expo@2.2.1/AzureADGraph.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// +------------------------------------------------------------------------------------------+\n// |                                                                                          |\n// | AzureADGraph.js                                                                          |\n// | ---------------                                                                          |\n// | Created by pinecat (https://github.com/pinecat/azure-ad-graph-expo)                      |\n// |                                                                                          |\n// | CONTRIBUTORS:                                                                            |\n// |  pinecat (https://github.com/pinecat)                                                    |\n// |  JuanDavidLopez95 (https://github.com/JuanDavidLopez95)                                  |\n// |                                                                                          |\n// | JavaScript library designed for use with Expo (https://expo.io).                         |\n// | This library follows Microsoft's Azure AD authentication flow using                      |\n// | Expo's own AuthSession to return user data from the Microsoft Graph                      |\n// | API (/me endpoint).                                                                      |\n// | You must register an app in Azure AD before you can authenticate using this method.      |\n// | AzureADGraph is NOT a react component.                                                   |\n// |                                                                                          |\n// | https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-overview              |\n// | https://docs.microsoft.com/en-us/graph/use-the-api                                       |\n// |                                                                                          |\n// +------------------------------------------------------------------------------------------+\n\n/* imports */\nimport * as AuthSession from 'expo-auth-session'; // AuthSession: for opening the authorization URL\n\n/*\n    callMsGraph\n      queries the Microsoft Graph API to return user data\n      params:   token - the unique token used to query the logged in user in the Graph API\n      returns:  graphResponse - a JSON object of the user data\n*/\nconst callMsGraph = async (token) => {\n  /* make a GET request using fetch and querying with the token */\n  let graphResponse = null;\n  await fetch('https://graph.microsoft.com/v1.0/me', {\n    method: 'GET',\n    headers: {\n      'Authorization': 'Bearer ' + token,\n    }\n  })\n  .then((response) => response.json())\n  .then((response) => {\n    graphResponse = response;\n  })\n  .catch((error) => {\n    graphResponse = error;\n  });\n  \n  /* \n    Spread the results of the graph and add a type property with a value of success to indicate\n    that the AzureAD info grabbing was a success\n  */ \n  const finalResponse = {\n    ...graphResponse,\n    type: \"success\"\n  }\n\n  return finalResponse;\n}; //end callMsGraph()\n\n/*\n  getToken\n        sends POST request to MS Azure AD token endpoint to get a token that can be used to\n        query the MS Graph API.  also forms the body to be send in the POST request\n        params:   code - the code that was recieved when the user logged in via Azure\n                props - the Azure AD app properties used to construct the request\n        returns:  callMsGraph() - callMsGraph will return the user data from the Graph API\n*/\nconst getToken = async (code, props) => {\n    /* parse/gather correct key values for the POST request to the token endpoint */\n    /* Client secret is omitted here; including it yields an error */\n    var requestParams = {\n      client_id: props.clientId,\n      scope: props.scope,\n      code: code,\n      redirect_uri: props.redirectUrl,\n      grant_type: 'authorization_code',\n    }\n  \n    /* loop through object and encode each item as URI component before storing in array */\n    /* then join each element on & */\n    /* request is x-www-form-urlencoded as per docs: https://docs.microsoft.com/en-us/graph/use-the-api */\n    var formBody = [];\n    for (var p in requestParams) {\n      var encodedKey = encodeURIComponent(p);\n      var encodedValue = encodeURIComponent(requestParams[p]);\n      formBody.push(encodedKey + '=' + encodedValue);\n    }\n    formBody = formBody.join('&');\n  \n    /* make a POST request using fetch and the body params we just setup */\n    let tokenResponse = null;\n    await fetch(`https://login.microsoftonline.com/${props.tenantId}/oauth2/v2.0/token`, {\n      method: 'POST',\n      headers: {\n        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'\n      },\n      body: formBody,\n    })\n    .then((response) => response.json())\n    .then((response) => {\n      tokenResponse = response;\n    })\n    .catch((error) => {\n      console.error(error);\n    });\n    return {\n      ...await callMsGraph(tokenResponse.access_token),\n      tokenResponse,\n    }\n}; //end getToken()\n\n/*\n  openAuthSession\n    opens connection to the azure ad authentication url using Expo's AuthSession\n    params:   props - a JSON object of your app properies (i.e. clientId, tenantId, etc)\n    returns:  getToken() - calls getToken which calls callMsGraph to return the user data from the Graph API\n*/\nconst openAuthSession = async (props) => {\n  const authUrl = `https://login.microsoftonline.com/${props.tenantId}/oauth2/v2.0/authorize?client_id=${props.clientId}&response_type=code&scope=${encodeURIComponent(props.scope)}${props.domainHint ? \"&domain_hint=\" + encodeURIComponent(props.domainHint) : null}${props.prompt ? \"&prompt=\" + props.prompt : null}&redirect_uri=${encodeURIComponent(props.redirectUrl)}`;\n\n  /*\n    Add a returnUrl parameter to the AuthSession.startAsync() config object.\n    If undefined, fall back to AuthSession.makeRedirectUri().\n    Strange bug on Android --\n    Without this, even if authentication is successful, the result of authResponse will always \n    be { type: 'dismiss' }\n\n    Source :\n        https://docs.expo.io/versions/latest/sdk/auth-session/#authsessionstartasyncoptions\n  */ \n  \n  let authResponse = await AuthSession.startAsync({\n      authUrl     :   authUrl,\n      returnUrl   :   props.returnUrl || AuthSession.makeRedirectUri()\n    })\n    .then((authResponse ) => { \n          //Conditional if the user proceeds with the authentication process\n          if (authResponse.type === \"success\") { \n\n          /*\n            Only continue with the authentication process if user does not cancel or close \n            the ongoing authentication window or session. authResponse and the code from \n            the parameters will be defined if the authorization session continues. \n          */\n          \n            //Do not proceed with acquiring a token if there is an error. Return the error and the response.\n            if (authResponse.params[\"error\"] ) {\n\n              /* \n                Return error as an added error property value in the object for easier \n                catching of the error in the front end \n              */\n              return { \n                      \"error\": authResponse.params.error,\n                      ...authResponse\n                    };\n            } else {\n              //If authentication is successful, pass the authorization code to get the token\n              return getToken(authResponse.params.code, props);\n            }\n\n          } //end if-statement\n          //Else statement to catch if the user has decline continuing further with authentication.\n          else { \n            //Return the authResponse which wil include a type of dismissed or cancelled. \n            return { \n              \"error\": \"Authorization session cancelled\",\n              ...authResponse\n            };\n          } //end else-statement.\n    })\n    .catch((error) => {\n      console.error(error);\n      return { \n          \"error\" : error , \n          \"type\": \"error\"\n        };\n    });\n\n    //Return the final authResponse that resolves from the promise.\n    return authResponse;\n}; //end openAuthSession()\n\nexport { openAuthSession };"]}