Пример #1
0
    private IEnumerator GenerateRefreshTokenRequest(string code, string clientId, string clientSecret, string redirectUrl)
    {
        WWWForm requestForm = new WWWForm();

        requestForm.AddField("grant_type", "authorization_code");
        requestForm.AddField("code", code);
        requestForm.AddField("client_id", clientId);
        requestForm.AddField("client_secret", clientSecret);
        requestForm.AddField("redirect_uri", redirectUrl);

        WWW response = new WWW("https://accounts.google.com/o/oauth2/token", requestForm);

        yield return(response);

        if (string.IsNullOrEmpty(response.error))
        {
            Dictionary <string, object> data = ANMiniJSON.Json.Deserialize(response.text) as Dictionary <string, object>;
            string access_token  = data.ContainsKey("access_token") ? data ["access_token"].ToString() : string.Empty;
            string refresh_token = data.ContainsKey("refresh_token") ? data ["refresh_token"].ToString() : string.Empty;
            string token_type    = data.ContainsKey("token_type") ? data ["token_type"].ToString() : string.Empty;
            long   expiresIn     = data.ContainsKey("expires_in") ? (long)data ["expires_in"] : 0L;

            AN_RefreshTokenResult result = new AN_RefreshTokenResult(true, access_token, refresh_token, token_type, expiresIn);
            OnOAuthRefreshTokenLoaded(result);
        }
        else
        {
            AN_RefreshTokenResult result = new AN_RefreshTokenResult(false, response.error);
            OnOAuthRefreshTokenLoaded(result);
        }
    }
Пример #2
0
    //--------------------------------------
    // Event Handlers
    //--------------------------------------

    private void RefreshTokenCodeReceived(string data)
    {
        Debug.Log(data);
        string[] rawData = data.Split(new string[] { "|" }, StringSplitOptions.None);
        int      status  = Int32.Parse(rawData [0]);

        if (status == 1)
        {
            StartCoroutine(GenerateRefreshTokenRequest(rawData [1], _clientId, _clientSecret, _redirectUrl));
        }
        else
        {
            AN_RefreshTokenResult result = new AN_RefreshTokenResult(false, "Request Authorization Code error");
            OnOAuthRefreshTokenLoaded(result);
        }
    }