• Kartik Gupta
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I'm an OAuth noob and strugging to get a login page to pop up where Apex is the client and GoToWebinar is the Service.  How do I make the login screen pop up?  Does it somehow magically take over the VF page via redirect or do I need some javascript to open a new window?  Below is my attempted approach using HttpRequest:

 

My first attempt is something like this:

public class G2WButtonController{
    public G2WButtonController(ApexPages.StandardController stdController){
    }
    
    //Code that will run upon button click
    public void autoRun(){
        callG2W(args);
    }

    public static void callG2W(String[] args) 
    {
        String postURL='https://api.citrixonline.com/oauth/authorize?client_id=<myClientId>';
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(postURL);
        req.setMethod('POST');
        HttpResponse res = http.send(req);

        //Class to parse the results
        XmlStreamReader reader = res.getXmlStreamReader();
    }
}

 VF

<apex:page standardController="G2W_Login__c" extensions="G2WButtonController" action="{!autoRun}">
  <apex:pagemessages />

    <apex:sectionHeader title="Auto-Running Apex Code"/>
  <apex:outputPanel >
      You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have
      been redirected back to the record you clicked the button from.
  </apex:outputPanel>

</apex:page>

 Once I get the login page to pop up, I'm assuming I would then parse the HttpResponse to get a param from the redirect URL- is that correct?

 

Any code samples others have would be greatly appreciated!