title: How to fetch AccessToken
body: <p>I am using the following plugin( @axa-fr/react-oidc-context ) in React to enable authentication with AzureAd. Now I need to access the access_token in ApolloClient after the authentication is done. I am not sure how to fetch the access_token in non react component like ApolloClient.</p>
  
  <p>Here is what i am doing.</p>
  
  <p>App.js</p>
  
  <pre><code>import React from "react";
  import { HashRouter, Route, Switch } from "react-router-dom";
  import { AuthenticationProvider, withOidcSecure } from "@axa-fr/react-oidc-context";
  import { IDENTITY_CONFIG } from "./utils/configuration";
  // components
  import Layout from "./Layout";
  
  export default function App() {
    return (
      &lt;AuthenticationProvider configuration={IDENTITY_CONFIG}&gt;
        &lt;HashRouter&gt;
          &lt;Switch&gt;
            &lt;Route path="/" component={withOidcSecure(Layout)} /&gt;
          &lt;/Switch&gt;
        &lt;/HashRouter&gt;
      &lt;/AuthenticationProvider&gt;
    );
  }
  </code></pre>
  
  <p>Layout.js</p>
  
  <pre><code>import React from "react";
  import { Route, Switch, withRouter } from "react-router-dom";
  import { ApolloProvider } from "@apollo/react-hooks";
  import client from "./apollo";
  
  import Dashboard from "./pages/dashboard";
  
  function Layout(props) {
    return (
      &lt;&gt;
        &lt;ApolloProvider client={client}&gt;
          &lt;Switch&gt;
            &lt;Route exact path="/" component={Dashboard} /&gt;
          &lt;/Switch&gt;
        &lt;/ApolloProvider&gt;
      &lt;/&gt;
    );
  }
  
  export default withRouter(Layout);
  </code></pre>
  
  <p>apollo.js</p>
  
  <pre><code>import { InMemoryCache } from "apollo-cache-inmemory";
  import { ApolloClient } from "apollo-client";
  import { ApolloLink, split } from "apollo-link";
  import { setContext } from "apollo-link-context";
  import { HttpLink } from "apollo-link-http";
  import { WebSocketLink } from "apollo-link-ws";
  import { getMainDefinition } from "apollo-utilities";
  
  import { useReactOidc } from "@axa-fr/react-oidc-context";
  
  const { oidcUser } = useReactOidc();
  
  console.log(oidcUser.access_token)
  
  const httpUri = process.env.REACT_APP_SERVER_URL
    ? process.env.REACT_APP_SERVER_URL
    : "https://48p1r2roz4.sse.codesandbox.io";
  const wsUri = httpUri.replace(
    /^https?/,
    process.env.REACT_APP_ENV === "dev" ? "ws" : "wss"
  );
  
  const httpLink = new HttpLink({
    uri: httpUri
  });
  
  const wsLink = new WebSocketLink({
    uri: wsUri,
    options: {
      lazy: true,
      reconnect: true
      // connectionParams: () =&gt; {
      //   return { headers: { Authorization: getAuthHeader() } };
      // }
    }
  });
  
  const authLink = setContext((_, { headers }) =&gt; {
    //   const auth = getAuthHeader()
  
    return {
      headers: {
        ...headers
        //   Authorization: auth,
      }
    };
  });
  
  const terminatingLink = split(
    ({ query }) =&gt; {
      const { kind, operation } = getMainDefinition(query);
      return kind === "OperationDefinition" &amp;&amp; operation === "subscription";
    },
    wsLink,
    authLink.concat(httpLink)
  );
  
  const link = ApolloLink.from([terminatingLink]);
  const cache = new InMemoryCache();
  
  const client = new ApolloClient({
    link,
    cache
  });
  
  export default client;
  </code></pre>
  
  <p>I am trying to pull the access token in apollo.js file, but it's throwing error where it says I cannot access React Hooks in Non React component.</p>