Esempio n. 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);
            }
        }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
 /// <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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }
Esempio n. 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")
 {
 }