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