/// <summary>
        /// Login using the specified raw token.
        /// </summary>
        /// <param name="refreshToken">A raw token.</param>
        /// <returns>Token Object</returns>
        public async Task Login(string refreshToken)
        {
            if (this.AuthorizationEndpoint == null)
            {
                var info = await this.Info.GetInfo();

                this.AuthorizationEndpoint = new Uri(info.AuthorizationEndpoint);
            }

            var data = new List <KeyValuePair <string, string> >();

            data.Add(new KeyValuePair <string, string>("grant_type", "refresh_token"));
            data.Add(new KeyValuePair <string, string>("refresh_token", refreshToken));

            var authUrl = new Uri(AuthorizationEndpoint.ToString().TrimEnd('/') + "/oauth/token");

            this.token = await PostFormUrlEncoded(authUrl.AbsoluteUri, data);

            //if (context.IsLoggedIn)
            {
                //// Workaround for HCF. Some CC requests (e.g. dev role + bind route, update app, etc..) will fail the first time after login with 401.
                //// Calling the CC's /v2/info endpoint will prevent this misbehavior.
                await this.Info.GetInfo();
            }

            //return context;
        }
Exemple #2
0
        public async Task <AuthenticationContext> Login(string refreshToken)
        {
            if (this.AuthorizationEndpoint == null)
            {
                var info = await this.V2.Info.GetInfo();

                this.AuthorizationEndpoint = new Uri(info.AuthorizationEndpoint);
            }

            var authUrl = new Uri(AuthorizationEndpoint.ToString().TrimEnd('/') + "/oauth/token");

            this.UAAClient = new UAAClient(authUrl, this.HttpProxy, this.SkipCertificateValidation);

            var context = await this.UAAClient.Login(refreshToken);

            await this.V2.Login(refreshToken);

            if (context.IsLoggedIn)
            {
                //// Workaround for HCF. Some CC requests (e.g. dev role + bind route, update app, etc..) will fail the first time after login with 401.
                //// Calling the CC's /v2/info endpoint will prevent this misbehavior.
                await this.V2.Info.GetInfo();
            }

            return(context);
        }
        /// <summary>
        /// Login using the specified credentials.
        /// </summary>
        /// <param name="credentials">The credentials.</param>
        /// <returns>Refresh Token</returns>
        public async Task Login(string username, string password)
        {
            if (this.AuthorizationEndpoint == null)
            {
                var info = await this.Info.GetInfo();

                this.AuthorizationEndpoint = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}", info.AuthorizationEndpoint.TrimEnd('/'), "/oauth/token"));
            }

            var authUrl = new Uri(AuthorizationEndpoint.ToString().TrimEnd('/') + "/oauth/token");

            //var client = new HttpClient();
            var data = new List <KeyValuePair <string, string> >();

            data.Add(new KeyValuePair <string, string>("grant_type", "password"));
            data.Add(new KeyValuePair <string, string>("username", username));
            data.Add(new KeyValuePair <string, string>("password", password));

            this.token = await PostFormUrlEncoded(authUrl.AbsoluteUri, data);

            //if (context.IsLoggedIn)
            {
                //// Workaround for HCF. Some CC requests (e.g. dev role + bind route, update app, etc..) will fail the first time after login with 401.
                //// Calling the CC's /v2/info endpoint will prevent this misbehavior.
                await this.Info.GetInfo();
            }
        }
        private AuthorisationResult AuthorizeV1()
        {
            if (!IsCurrentUserAuthorized())
            {
                if (!HaveVerificationCode())
                {
                    string ret = null;

                    string response = RequestToken();

                    if (response.Length > 0)
                    {
                        //response contains token and token secret. We only need the token.
                        NameValueCollection qs = HttpUtility.ParseQueryString(response);

                        if (qs[OAuthCallbackConfirmedKey] != null)
                        {
                            if (qs[OAuthCallbackConfirmedKey] != "true")
                            {
                                throw new Exception("OAuth callback not confirmed.");
                            }
                        }

                        if (qs[OAuthTokenKey] != null)
                        {
                            ret = AuthorizationEndpoint.ToString() + "?" + OAuthTokenKey + "=" + qs[OAuthTokenKey];

                            AuthToken   = qs[OAuthTokenKey];
                            TokenSecret = qs[OAuthTokenSecretKey];
                            SaveTokenCookie("_request");
                        }
                    }

                    HttpContext.Current.Response.Redirect(ret, true);

                    return(AuthorisationResult.RequestingCode);
                }

                ExchangeRequestTokenForToken();
            }

            return(AuthorisationResult.Authorized);
        }