예제 #1
0
파일: Connection.cs 프로젝트: Zefek/WLiveFW
        /// <summary>
        ///
        /// </summary>
        /// <param name="scopes">Scopes which you want to use</param>
        /// <param name="response_type">Access token, code, ...</param>
        /// <param name="isMobileApps">True when your app is mobile otherwise false</param>
        /// <returns>Returns Url for authorization</returns>
        public static Uri GetAuthorizationUrl(string[] scopes, string responseType, bool isMobileApps)
        {
            if (scopes == null)
            {
                throw new ArgumentNullException("scopes");
            }
            if (string.IsNullOrEmpty(responseType))
            {
                throw new ArgumentNullException("responseType");
            }
            QueryParameters qp  = new QueryParameters();
            string          ret = "";

            foreach (string s in scopes)
            {
                ret += s + ",";
            }
            if (ret.EndsWith(",", StringComparison.Ordinal))
            {
                ret = ret.Substring(0, ret.Length - 1);
            }
            qp.Add("scope", ret);
            qp.Add("response_type", responseType);
            if (isMobileApps)
            {
                qp.Add("display", "touch");
            }
            qp.Add("client_id", ClientId);
            qp.Add("client_secret", ClientSecret);
            qp.Add("redirect_uri", RedirectUri.ToString());
            return(UrlBuilder1.Concat(new Uri(UrlAuthorize), qp));
        }
예제 #2
0
파일: Connection.cs 프로젝트: Zefek/WLiveFW
        /// <summary>
        /// Gives new access token. Use this method for login or refreshing access token
        /// </summary>
        public static void LogOn()
        {
            QueryParameters qp = new QueryParameters();

            if (!string.IsNullOrEmpty(Connection.RefreshToken))
            {
                qp.Add("refresh_token", Connection.RefreshToken);
                GrantType = "refresh_token";
            }
            else
            {
                qp.Add("code", Code);
                GrantType = "authorization_code";
            }
            qp.Add("grant_type", GrantType);
            qp.Add("client_id", ClientId);
            qp.Add("client_secret", ClientSecret);
            qp.Add("redirect_uri", RedirectUri.ToString());
            try
            {
                connection = Requester.Request <Connection>(new RequestObject {
                    Url = UrlBuilder1.Concat(new Uri(UrlToken), qp)
                }).ElementAt(0);
            }
            catch
            {
                throw;
            }
        }