public static void GetAccessToken(Action <string> onSuccess)
    {
        var url  = @"https://www.googleapis.com/oauth2/v4/token";
        var form = new WWWForm();

        form.AddField("grant_type", @"urn:ietf:params:oauth:grant-type:jwt-bearer");
        form.AddField("assertion", GoogleJsonWebToken.Create(email, Application.dataPath + "/" + keyFile, keyPassword));
        PostRequest(url, form, null, null, onSuccess);
    }
コード例 #2
0
    IEnumerator GetAccessToken()
    {
        string jwt = GoogleJsonWebToken.GetJwt(
            email, certPath, GoogleJsonWebToken.SCOPE);
        WWW tokenRequest = GoogleJsonWebToken.GetAccessTokenRequest(jwt);

        yield return(tokenRequest);

        if (tokenRequest.error == null)
        {
            var deserializedResponse = JObject.Parse(tokenRequest.text);
            this.ACCESS_TOKEN = (string)deserializedResponse["access_token"];
            Debug.Log("Access Token Obtained: " + this.ACCESS_TOKEN);
        }
        else
        {
            Debug.Log("ERROR: " + tokenRequest.text);
        }
    }
コード例 #3
0
        /// <summary>
        /// Acquires a new JWT token and updates the cache.
        /// </summary>
        /// <param name="credentialsFileName">The name of the .p12 file that contains the credentials.</param>
        /// <param name="serviceAccount">The name of the service account which is making the request.</param>
        public static IEnumerator GetToken(string credentialsFileName, string serviceAccount)
        {
            TextAsset p12File = Resources.Load <TextAsset>(credentialsFileName);
            var       jwt     = GoogleJsonWebToken.GetJwt(serviceAccount, p12File.bytes,
                                                          GoogleJsonWebToken.SCOPE_DIALOGFLOWV2);
            UnityWebRequest tokenRequest = GoogleJsonWebToken.GetAccessTokenRequest(jwt);

            yield return(tokenRequest.SendWebRequest());

            if (tokenRequest.isNetworkError || tokenRequest.isHttpError)
            {
                Debug.LogError("Error " + tokenRequest.responseCode + ": " + tokenRequest.error);
                yield break;
            }
            string serializedToken = Encoding.UTF8.GetString(tokenRequest.downloadHandler.data);
            var    jwtJson         = JsonConvert.DeserializeObject <GoogleJsonWebToken.JwtTokenResponse>(serializedToken);

            tokens[serviceAccount] = new JwtToken(jwtJson.access_token,
                                                  Time.time + jwtJson.expires_in);
        }
 public static void CreateJWTTest()
 {
     Debug.Log(GoogleJsonWebToken.Create(email, Application.dataPath + "/" + keyFile, keyPassword));
 }