Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new client to interact with Uber's API
 /// </summary>
 /// <param name="clientid"></param>
 /// <param name="clientsecret"></param>
 /// <param name="redirect_uri"></param>
 /// <param name="scope"></param>
 public UberClient(string clientid, string clientsecret, string redirect_uri, string[] scope)
 {
     UberConstants.ClientId = clientid;
     UberConstants.StoreSecret(UberConstants.ClientSecretUserName, clientsecret);
     this.redirect_uri = redirect_uri;
     this.scope        = scope;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Oauth2.0 Flow for Uber
        /// </summary>
        /// <param name="clientID">ClientID of the Uber app</param>
        /// <param name="redirect_uri">Redirect URI</param>
        /// <param name="scope">List of space delimited scopes to request from Uber</param>
        public static async Task <bool> Oauth2Flow(string clientID, string redirect_uri, string clientsecret, string scope)
        {
            if (!String.IsNullOrEmpty(UberConstants.ReadSecret(UberConstants.ClientSecretUserName)))
            {
                return(true);
            }

            WebAuthenticationResult authCodeResult = await GetAuthorizationCode(clientID, redirect_uri, scope);

            if (authCodeResult.ResponseStatus == WebAuthenticationStatus.Success)
            {
                string   responseData    = authCodeResult.ResponseData.ToString();
                string   subResponseData = responseData.Substring(responseData.IndexOf("code"));
                String[] keyValPairs     = subResponseData.Split('=');
                string   authCode        = keyValPairs[1];

                Dictionary <string, string> pairs = new Dictionary <string, string>
                {
                    { "client_secret", clientsecret },
                    { "client_id", clientID },
                    { "grant_type", "authorization_code" },
                    { "redirect_uri", redirect_uri },
                    { "code", authCode }
                };

                HttpFormUrlEncodedContent formContent = new HttpFormUrlEncodedContent(pairs);

                HttpClient client = new HttpClient();
                var        httpresponseMessage = await client.PostAsync(new Uri(UberAPI.UberAccessTokenUrl), formContent);

                string response = await httpresponseMessage.Content.ReadAsStringAsync();

                UberAuthModel authResponse = JsonConvert.DeserializeObject <UberAuthModel>(response);
                UberConstants.StoreSecret(UberConstants.AccessTokenUserName, authResponse.access_token);
                UberConstants.StoreSecret(UberConstants.RefreshTokenUserName, authResponse.refresh_token);

                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
 public async void SignIn()
 {
     await AuthHelper.Oauth2Flow(UberConstants.ClientId, redirect_uri, UberConstants.ReadSecret(UberConstants.ClientSecretUserName), string.Join(" ", scope));
 }