Asana OAUTH2.0 Integration

25 views Asked by At
const AsanaIntegration = () => {
  const { isOpen, onOpen, onClose } = useDisclosure(); // Hook for managing modal state
  const [infoModalContent, setInfoModalContent] = useState("");// State to manage modal content  
  const router = useRouter();


        // Call the function to handle the access token exchange
      const clientID = process.env.ASANA_CLIENT_ID;
      const generateRandomState = () => {
        return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
      };
    const handleAsanaAuthentication = () => {
        // Construct the Asana OAuth 2.0 authorization URL
        const clientId =clientID; // Your Asana client ID
        const redirectUri = 'http://localhost:3000/dashboard'; // Your app's redirect URI
        const responseType = 'code';
        const state = generateRandomState();
        const scope = 'default'; // The permissions your app is requesting
    
        const authorizationUrl = `https://app.asana.com/-/oauth_authorize?response_type=code&client_id=${clientId}&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fdashboard&state=${state}`;
     
        // Redirect the user to the Asana authorization page
        window.location.href = authorizationUrl;
      };
      useEffect(() => {
        
          const querystring = new URLSearchParams(window.location.search);
        const code = querystring.get('code');
        if (code) {
          console.log('OAuth code:', code);
          // router.push('/dashboard');
        }
      }, []);

I am trying OAUTH2.0 integration for asana in my next-js app , so I have set up the project in asana developer console , and as the first step I am successfully getting redirected to the auth URL , but I am unable to extract that code from auth URL , I cant proceed further to decode that code and use that code to exchange for accesstoken . Which step I am doing wrong?

0

There are 0 answers