コード例 #1
0
ファイル: AuthHelper.cs プロジェクト: agangal/UberHelper
        /// <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);
        }
コード例 #2
0
ファイル: UberClient.cs プロジェクト: agangal/UberHelper
 public async void SignIn()
 {
     await AuthHelper.Oauth2Flow(UberConstants.ClientId, redirect_uri, UberConstants.ReadSecret(UberConstants.ClientSecretUserName), string.Join(" ", scope));
 }