예제 #1
0
        /// <summary>
        /// Starts the authentication operation with a given settings.
        /// </summary>
        /// <param name="this">Instance of <see cref="InTouch"/>.</param>
        /// <param name="authSettings">Authorization settings</param>
        /// <param name="silentMode">Tells the web authentication broker to not render any UI.</param>
        /// <exception cref="InTouchException">Thrown when a HTTP error occurred or inner exceptions were caught.</exception>
        /// <returns></returns>
        public static async Task Authorize(this InTouch @this, AuthorizationSettings authSettings = null, bool silentMode = false)
        {
            var ad = authSettings ?? new AuthorizationSettings();

            if (@this.ClientId == 0)
            {
                throw new NullReferenceException("ClientId cannot be null or empty");
            }

            var authParams = new Dictionary <string, object>
            {
                { "client_id", @this.ClientId },
                { "v", @this.APIVersion },
                { "scope", (int)ad.Scope },
                { "display", Utils.ToEnumString(ad.Display) },
                { "response_type", "token" },
                { "revoke", ad.Revoke ? 1 : 0 },
                { "redirect_uri", ad.RedirectUri },
                { "lang", "en" }
            };

            var authUrl = new Uri($"{AuthUrl}?{authParams.GetQueryString()}");
            var endUrl  = new Uri($"{ad.RedirectUri}#access_token=");
            var wao     = silentMode ? WebAuthenticationOptions.SilentMode : WebAuthenticationOptions.None;

            try
            {
                WebAuthenticationResult webAuthResult;

                if (ad.SSOEnabled)
                {
                    webAuthResult = await WebAuthenticationBroker.AuthenticateAsync(wao, authUrl);
                }
                else
                {
                    webAuthResult = await WebAuthenticationBroker.AuthenticateAsync(wao, authUrl, endUrl);
                }

                if (webAuthResult.ResponseStatus == WebAuthenticationStatus.Success)
                {
                    var responseData =
                        Utils.ParseQueryString(webAuthResult.ResponseData.Substring(ad.RedirectUri.ToString().Length + 1));

                    @this.SetSessionData(responseData["access_token"], int.Parse(responseData["user_id"]),
                                         int.Parse(responseData["expires_in"]));
                }
                else if (webAuthResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
                {
                    throw new InTouchException("A HTTP error occurred while attempting to contact the server.", webAuthResult.ResponseErrorDetail);
                }
                else
                {
                    throw new InTouchException("An error occurred while attempting to authorize.", webAuthResult.ResponseStatus);
                }
            }
            catch (Exception ex)
            {
                throw new InTouchException("An exception has occurred while authenticating.", ex);
            }
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PagesMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal PagesMethods(InTouch api) : base(api, "pages")
 {
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WallMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal WallMethods(InTouch api) : base(api, "wall")
 {
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PollsMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal PollsMethods(InTouch api) : base(api, "polls")
 {
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AccountMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal AccountMethods(InTouch api) : base(api, "account")
 {
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BoardMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public BoardMethods(InTouch api) : base(api, "board")
 {
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StatsMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal StatsMethods(InTouch api) : base(api, "stats")
 {
 }
예제 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DatabaseMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public DatabaseMethods(InTouch api) : base(api, "database")
 {
 }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessagesMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal MessagesMethods(InTouch api) : base(api, "messages")
 {
 }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BoardMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal BoardMethods(InTouch api) : base(api, "board")
 {
 }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessagesMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public MessagesMethods(InTouch api) : base(api, "messages")
 {
 }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NotificationsMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public NotificationsMethods(InTouch api) : base(api, "notifications")
 {
 }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal SearchMethods(InTouch api) : base(api, "search")
 {
 }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DocsMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public DocsMethods(InTouch api) : base(api, "docs")
 {
 }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GroupsMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal GroupsMethods(InTouch api) : base(api, "groups")
 {
 }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FaveMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal FaveMethods(InTouch api) : base(api, "fave")
 {
 }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GiftsMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public GiftsMethods(InTouch api) : base(api, "gifts")
 {
 }
예제 #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DatabaseMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal DatabaseMethods(InTouch api) : base(api, "database")
 {
 }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AccountMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public AccountMethods(InTouch api) : base(api, "account")
 {
 }
예제 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal AuthMethods(InTouch api) : base(api, "auth")
 {
 }
예제 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StorageMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public StorageMethods(InTouch api) : base(api, "storage")
 {
 }
예제 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PagesMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public PagesMethods(InTouch api) : base(api, "pages")
 {
 }
예제 #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UsersMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public UsersMethods(InTouch api) : base(api, "users")
 {
 }
예제 #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NewsfeedMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public NewsfeedMethods(InTouch api) : base(api, "newsfeed")
 {
 }
예제 #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AudioMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal AudioMethods(InTouch api) : base(api, "audio")
 {
 }
예제 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MarketMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public MarketMethods(InTouch api) : base(api, "market")
 {
 }
예제 #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GroupsMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public GroupsMethods(InTouch api) : base(api, "groups")
 {
 }
예제 #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 public AuthMethods(InTouch api) : base(api, "auth")
 {
 }
예제 #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DocsMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal DocsMethods(InTouch api) : base(api, "docs")
 {
 }
예제 #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PlacesMethods"/> class with a given <see cref="InTouch"/> instance.
 /// </summary>
 /// <param name="api">An instance of <see cref="InTouch"/> class.</param>
 internal PlacesMethods(InTouch api) : base(api, "places")
 {
 }