Пример #1
0
        public async Task <Dictionary <string, string> > Auth()
        {
            SettingsHelper.SetLocalValue(isAuthIntendedKey, false);
            JObject config = await secretsProvider.GetSecrets();

            Uri uri    = new Uri(string.Format(authUrlPattern, config["Client_Id"]));
            var result = await AuthBroker.AuthenticateAsync(uri, new Uri(callback));

            if (result.ResponseStatus == AuthResponseStatus.ErrorHttp)
            {
                throw new AuthException($"Error Code: {result.ErrorDetail}");
            }
            else if (result.ResponseStatus == AuthResponseStatus.UserCancel)
            {
                throw new AuthException($"User cancelled the auth process");
            }
            SettingsHelper.SetLocalValue(isAuthIntendedKey, true);

            //result.ResponseData[expiresAtKey] = DateTime.Now.AddSeconds(int.Parse(ret["expires_in"])).ToString();
            //Imgur API is a liar. It says the token is valid for a month but expires it in an hour anyway.
            if (result.ResponseData != null)
            {
                result.ResponseData[expiresAtKey] = DateTime.Now.AddSeconds(3600).ToString();
            }
            return(result.ResponseData);
        }
Пример #2
0
        private async void Init(ISecretsProvider secretsProvider)
        {
            var allConfig = await secretsProvider.GetSecrets();

            var config = allConfig["Ad_Config"];

            appKey   = (string)config["App_Key"];
            bannerId = (string)config["Banner_Id"];
            AdDuplex.AdDuplexClient.Initialize(appKey);
        }
Пример #3
0
        public async Task <AuthResult> AuthenticateAsync(Uri requestUri, Uri callbackUri)
        {
            var auth = await BuildAuthenticator(requestUri, callbackUri);

            var tcs = new TaskCompletionSource <AuthenticatorCompletedEventArgs>();

            auth.Completed += (s, e) => tcs.SetResult(e);
            context.StartActivity(auth.GetUI(context));
            var args = await tcs.Task;

            if (args.IsAuthenticated)
            {
                var          props  = args.Account.Properties;
                const string url    = "https://api.imgur.com/oauth2/token";
                var          config = await secretsProvider.GetSecrets();

                string  clientId     = (string)config["Client_Id"];
                string  clientSecret = (string)config["Client_Secret"];
                JObject payload      = new JObject();
                payload["refresh_token"] = props["refresh_token"];
                payload["client_id"]     = clientId;
                payload["client_secret"] = clientSecret;
                payload["grant_type"]    = "refresh_token";

                string resultString = await httpClient.PostAsync(new Uri(url), payload.ToString(), default(CancellationToken), null);

                //NetworkHelper.ExecutePostRequest(url, payload, false);
                JObject result = JObject.Parse(resultString);
                Dictionary <string, string> ret = new Dictionary <string, string>();
                ret["account_username"] = (string)result["account_username"];
                ret["access_token"]     = (string)result["access_token"];
                ret["refresh_token"]    = (string)result["refresh_token"];
                ret["expires_at"]       = (string)result["expires_at"];
                return(new AuthResult(ret, AuthResponseStatus.Success));
            }
            else
            {
                return(new AuthResult(args.Account?.Properties, AuthResponseStatus.UserCancel));
            }
        }
Пример #4
0
 public async Task <JObject> GetConfiguration()
 {
     return(await secretsProvider.GetSecrets());
 }