Search Unity

Getting Access Key for OAuth 2.0 Authentication

Discussion in 'Scripting' started by AbraxasQ, Jan 24, 2015.

  1. AbraxasQ

    AbraxasQ

    Joined:
    Jan 24, 2015
    Posts:
    4
    I'm a new comer studying server communication with Unity 4.5

    I have been following a OAuth 2.0 guide(Pic. below) provided from the server I want to communicate with.

    And with communication tutorial(http://unity-tutorials.blogspot.ca/), tried to follow the guide using WWW in Javascript.

    But the guide is too ambiguous to me, 2 headers? 1 Body? How do I specify them in the WWWForm? I tried simply modifying the values in AddField portion of the tutorial but it gave me an error:

    Error: Rejected because no crossdomain.xml policy file was found
    UnityEngine.Debug:Log(Object)
    $:MoveNext() (at Assets/Scripts/StartMenu/LoginService.js:27)


    The portion of code modified from the tutorial:

    Code (JavaScript):
    1. public function sendLoginData(loginData : LoginData, responseHandler) {
    2.      
    3.         var response : Response = new Response();
    4.      
    5.         Debug.Log("Sending login request to " + LOGIN_URL);
    6.      
    7.         // Creating form with login and password fields to send using POST method:
    8.         var loginForm = new WWWForm();
    9.  
    10.         [COLOR=#000000]loginForm.AddField("Authorization","eDJlcFpCNzRTOXFxMnBTdxT3Z2dzo1aVNmbW1PTzUyUG12N0N3");
    11.         loginForm.AddField("Content-Type", "application/xwwwformurlencoded");
    12.         loginForm.AddField("BODY", "grant_type=client_credentials");[/COLOR]
    13.  
    14.         // Sending request:
    15.         var httpResponse = new WWW(LOGIN_URL, loginForm);
    16.  
    17.         // Waiting for response:
    18.         yield httpResponse;
    I've been googling and searching in forum for answers, but I couldn't find (or understand) how to properly do this. It just made me realize it's not simple as I hoped.
    Untitled-4.jpg
    Untitled-2.jpg
     

    Attached Files:

    Last edited: Jan 25, 2015
  2. TEvashkevich

    TEvashkevich

    Joined:
    May 14, 2015
    Posts:
    9
    I came across this post a bunch when I was trying to figure out how to do oauth in unity. Finally figured it out myself so now I'm going and sharing my results in a post I made.

    http://technicalartistry.blogspot.be/2015/07/oauth2-unity-and-month-of-cursing.html?m=1

    Give it a look and hope it helps.

    EDIT:
    For those that come after me, There is also this new blogpost about doing OAuth in Unity for Android WITHOUT a webview (so free :D)
    http://technicalartistry.blogspot.ca/2016/01/fitbit-unity-oauth-2-and-native.html
     
    Last edited: Jan 13, 2016
    iamvideep and tcmeric like this.