Exemplo n.º 1
0
        private void authButton_Click(object sender, EventArgs e)
        {
            var grantType    = "client_credentials";                          // string | Method of authentication
            var clientId     = "yWELzn_u";                                    // string | Required for grant type `client_credentials` and `client_signature`
            var clientSecret = "gjF0ypJxao-8hmycbfgemBCjTtRnR9MMLxFxSkVoMyA"; // string | Required for grant type `client_credentials`
            var scope        = "session:box trade:read_write";                // string | Describes type of the access for assigned token, possible values: `connection`, `session`, `session:name`, `trade:[read, read_write, none]`, `wallet:[read, read_write, none]`, `account:[read, read_write, none]`, `expires:NUMBER` (token will expire after `NUMBER` of seconds).</BR></BR> **NOTICE:** Depending on choosing an authentication method (```grant type```) some scopes could be narrowed by the server. e.g. when ```grant_type = client_credentials``` and ```scope = wallet:read_write``` it's modified by the server as ```scope = wallet:read``` (optional)

            try {
                // Authenticate
                Object rootResponse = authApiInstance.PublicAuthGet(grantType, Configuration.Default.Username, Configuration.Default.Password, clientId, clientSecret, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, scope: scope);
                MessageBox.Show(rootResponse.ToString());
                var settings = new JsonSerializerSettings {
                    Converters =
                    {
                        new ForeignJsonNetContainerConverter(), new ForeignJsonNetValueConverter()
                    },
                };
                settings.Formatting = Formatting.Indented;
                RootAuthApi rootResponseObj = JsonConvert.DeserializeObject <RootAuthApi>(rootResponse.ToString(), settings);
                //Clipboard.SetText(rootResponse.ToString());
                AuthResult authRes = rootResponseObj.Result;
                refreshToken = authRes.RefreshToken;
                Configuration.Default.AccessToken = accessToken = authRes.AccessToken.Trim();
                refreshTokenTimer.Enabled         = true;
            } catch (ApiException ex) {
                MessageBox.Show("Exception when calling AuthenticationApi.PublicAuthGet: " + ex.Message);
                MessageBox.Show("Status Code: " + ex.ErrorCode);
                MessageBox.Show(ex.StackTrace);
            }
        }