public OAuthTokens RefreshTokens() { try { var result = Request.SendPostRequest <OAuthTokenModel>(APIEndpoints.OAUTH_URL, new { app_context = Auth.AuthorizationBearer.AppContext, client_id = Auth.AuthorizationBearer.ClientId, client_secret = Auth.AuthorizationBearer.ClientSecret, refresh_token = Refresh, duid = Auth.AuthorizationBearer.Duid, grant_type = "refresh_token", scope = Auth.AuthorizationBearer.Scope }); _model = result; return(this); } catch (GenericAuthException ex) { switch (ex.Error.ErrorCode) { case 4159: throw new InvalidRefreshTokenException(ex.Error.ErrorDescription); default: throw; } } }
public async Task RefreshOAuthToken() { if (ChannelSession.User != null) { this.token = await this.GetAsync <OAuthTokenModel>("authentication?userID=" + ChannelSession.User.id); } }
/// <summary> /// Creates an OAuth token for authenticating with the Mixer services. /// </summary> /// <param name="clientID">The id of the client application</param> /// <param name="clientSecret">The secret key of the client application</param> /// <param name="authorizationCode">The authorization code</param> /// <param name="redirectUrl">The URL to redirect to after authorization is complete</param> /// <returns></returns> public async Task <OAuthTokenModel> GetOAuthTokenModel(string clientID, string clientSecret, string authorizationCode, string redirectUrl = null) { Validator.ValidateString(clientID, "clientID"); Validator.ValidateString(authorizationCode, "authorizationCode"); JObject payload = new JObject(); payload["grant_type"] = "authorization_code"; payload["client_id"] = clientID; payload["code"] = authorizationCode; if (!string.IsNullOrEmpty(clientSecret)) { payload["client_secret"] = clientSecret; } if (!string.IsNullOrEmpty(redirectUrl)) { payload["redirect_uri"] = redirectUrl; } OAuthTokenModel token = await this.PostAsync <OAuthTokenModel>("oauth/token", this.CreateContentFromObject(payload), autoRefreshToken : false); token.clientID = clientID; token.clientSecret = clientSecret; token.authorizationCode = authorizationCode; return(token); }
public override async Task <Result> Connect(OAuthTokenModel token) { try { SingleUserAuthorizer singleUserAuthorizer = new SingleUserAuthorizer { CredentialStore = new SingleUserInMemoryCredentialStore { ConsumerKey = TwitterService.ClientID, ConsumerSecret = ChannelSession.Services.Secrets.GetSecret("TwitterSecret"), AccessToken = token.accessToken, AccessTokenSecret = token.refreshToken, UserID = ulong.Parse(token.clientID), ScreenName = token.authorizationCode, } }; await singleUserAuthorizer.AuthorizeAsync(); this.authorizer = singleUserAuthorizer; return(await this.InitializeInternal()); } catch (Exception ex) { Logger.Log(ex); return(new Result(ex)); } }
/// <summary> /// Creates a constellation event client using the specified connection. /// </summary> /// <param name="connection">The connection to use</param> /// <returns>The constellation event client</returns> public static async Task <ConstellationClient> Create(MixerConnection connection) { Validator.ValidateVariable(connection, "connection"); OAuthTokenModel authToken = await connection.GetOAuthToken(); return(new ConstellationClient(authToken)); }
public OAuthTokens(string refreshToken) { this._model = new OAuthTokenModel { RefreshToken = refreshToken }; this.RefreshTokens(); }
private TwitchConnection(OAuthTokenModel token) { Validator.ValidateVariable(token, "token"); this.token = token; this.OAuth = new OAuthService(this); this.NewAPI = new NewTwitchAPIServices(this); }
/// <summary> /// Gets the HttpClient using the OAuth for the connection of this service. /// </summary> /// <param name="autoRefreshToken">Whether to automatically refresh the OAuth token or not if it has to be</param> /// <returns>The HttpClient for the connection</returns> protected virtual async Task <AdvancedHttpClient> GetHttpClient(bool autoRefreshToken = true) { OAuthTokenModel token = await this.GetOAuthToken(autoRefreshToken); if (token != null) { return(new AdvancedHttpClient(this.GetBaseAddress(), token)); } return(new AdvancedHttpClient(this.GetBaseAddress())); }
protected async Task <HttpClientWrapper> GetHttpClient() { OAuthTokenModel token = await this.GetOAuthToken(); if (token != null) { return(new HttpClientWrapper(this.GetBaseAddress(), token)); } return(new HttpClientWrapper(this.GetBaseAddress())); }
private TrovoConnection(OAuthTokenModel token) { Validator.ValidateVariable(token, "token"); this.token = token; this.OAuth = new OAuthService(this); this.Channels = new ChannelsService(this); this.Chat = new ChatService(this); this.Users = new UsersService(this); this.Categories = new CategoryService(this); }
private GlimeshConnection(OAuthTokenModel token) { Validator.ValidateVariable(token, "token"); this.token = token; this.OAuth = new OAuthService(this); this.Category = new CategoryService(this); this.Channel = new ChannelService(this); this.Users = new UsersService(this); }
/// <summary> /// Connects to the default ChatClient connection. /// </summary> /// <returns>An awaitable Task</returns> public async Task Connect() { await base.Connect(ChatClient.CHAT_CONNECTION_URL); OAuthTokenModel oauthToken = await this.connection.GetOAuthToken(); await this.Send("PASS oauth:" + oauthToken.accessToken); NewAPI.Users.UserModel user = await this.connection.NewAPI.Users.GetCurrentUser(); await this.Send("NICK " + user.login.ToLower()); }
public void RefreshToken() { TestWrapper(async(TwitchConnection connection) => { OAuthTokenModel token = connection.GetOAuthTokenCopy(); Assert.IsNotNull(token); await connection.RefreshOAuthToken(); token = connection.GetOAuthTokenCopy(); Assert.IsNotNull(token); }); }
/// <summary> /// Creates an interactive client using the specified connection to the specified channel and game. /// </summary> /// <param name="connection">The connection to use</param> /// <param name="channel">The channel to connect to</param> /// <param name="interactiveGame">The game to use</param> /// <returns>The interactive client for the specified channel and game</returns> public static async Task <InteractiveClient> CreateFromChannel(MixerConnection connection, ChannelModel channel, InteractiveGameListingModel interactiveGame) { Validator.ValidateVariable(connection, "connection"); Validator.ValidateVariable(channel, "channel"); Validator.ValidateVariable(interactiveGame, "interactiveGame"); OAuthTokenModel authToken = await connection.GetOAuthToken(); IEnumerable <string> interactiveConnections = await connection.Interactive.GetInteractiveHosts(); return(new InteractiveClient(channel, interactiveGame, authToken, interactiveConnections)); }
/// <summary> /// Gets the HttpClient using the OAuth for the connection of this service. /// </summary> /// <param name="autoRefreshToken">Whether to automatically refresh the OAuth token or not if it has to be</param> /// <returns>The HttpClient for the connection</returns> protected override async Task <AdvancedHttpClient> GetHttpClient(bool autoRefreshToken = true) { AdvancedHttpClient client = new AdvancedHttpClient(this.GetBaseAddress()); OAuthTokenModel token = await this.GetOAuthToken(autoRefreshToken); if (token != null) { client = new AdvancedHttpClient(this.GetBaseAddress(), "OAuth", token.accessToken); } client.DefaultRequestHeaders.Add("Client-ID", this.clientID); return(client); }
/// <summary> /// Creates an MixPlay client using the specified connection to the specified channel and game. /// </summary> /// <param name="connection">The connection to use</param> /// <param name="channel">The channel to connect to</param> /// <param name="game">The game to use</param> /// <param name="version">The version of the game to use</param> /// <param name="shareCode">The share code used to connect to a game shared with you</param> /// <returns>The MixPlay client for the specified channel and game</returns> public static async Task <MixPlayClient> CreateFromChannel(MixerConnection connection, ChannelModel channel, MixPlayGameModel game, MixPlayGameVersionModel version, string shareCode) { Validator.ValidateVariable(connection, "connection"); Validator.ValidateVariable(channel, "channel"); Validator.ValidateVariable(game, "game"); Validator.ValidateVariable(version, "version"); OAuthTokenModel authToken = await connection.GetOAuthToken(); IEnumerable <string> connections = await connection.MixPlay.GetMixPlayHosts(); return(new MixPlayClient(channel, game, version, shareCode, authToken, connections)); }
/// <summary> /// Creates a YouTubeLiveConnection object from an OAuth token. /// </summary> /// <param name="token">The OAuth token to use</param> /// <param name="refreshToken">Whether to refresh the token</param> /// <returns>The YouTubeLiveConnection object</returns> public static async Task <YouTubeConnection> ConnectViaOAuthToken(OAuthTokenModel token, bool refreshToken = true) { Validator.ValidateVariable(token, "token"); YouTubeConnection connection = new YouTubeConnection(token); if (refreshToken) { await connection.RefreshOAuthToken(); } return(connection); }
private Task InitializeInternal(IAuthorizer auth) { this.auth = auth; this.token = new OAuthTokenModel(); this.token.accessToken = this.auth.CredentialStore.OAuthToken; this.token.refreshToken = this.auth.CredentialStore.OAuthTokenSecret; this.token.clientID = this.auth.CredentialStore.UserID.ToString(); this.token.authorizationCode = this.auth.CredentialStore.ScreenName; return(Task.FromResult(0)); }
/// <summary> /// Creates a YouTubeLiveConnection object from an authorization code. /// </summary> /// <param name="clientID">The ID of the client application</param> /// <param name="clientSecret">The secret of the client application</param> /// <param name="authorizationCode">The authorization code for the authenticated user</param> /// <param name="redirectUrl">The redirect URL of the client application</param> /// <returns>The YouTubeLiveConnection object</returns> public static async Task <YouTubeConnection> ConnectViaAuthorizationCode(string clientID, string clientSecret, string authorizationCode, string redirectUrl = null) { Validator.ValidateString(clientID, "clientID"); Validator.ValidateString(authorizationCode, "authorizationCode"); OAuthService oauthService = new OAuthService(); OAuthTokenModel token = await oauthService.GetOAuthTokenModel(clientID, clientSecret, authorizationCode, redirectUrl); if (token == null) { throw new InvalidOperationException("OAuth token was not acquired"); } return(new YouTubeConnection(token)); }
protected override async Task RefreshOAuthToken() { if (this.token != null) { var body = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("grant_type", "refresh_token"), new KeyValuePair <string, string>("refresh_token", this.token.refreshToken), }; OAuthTokenModel token = await this.GetWWWFormUrlEncodedOAuthToken("https://accounts.spotify.com/api/token", SpotifyService.ClientID, ChannelSession.SecretManager.GetSecret("SpotifySecret"), body); token.refreshToken = this.token.refreshToken; this.token = token; } }
private MixerConnection(OAuthTokenModel token) { Validator.ValidateVariable(token, "token"); this.token = token; this.Channels = new ChannelsService(this); this.Chats = new ChatsService(this); this.Costream = new CostreamService(this); this.Interactive = new InteractiveService(this); this.OAuth = new OAuthService(this); this.Teams = new TeamsService(this); this.GameTypes = new GameTypesService(this); this.Users = new UsersService(this); }
/// <summary> /// Gets the HttpClient using the OAuth for the connection of this service. /// </summary> /// <param name="autoRefreshToken">Whether to automatically refresh the OAuth token or not if it has to be</param> /// <returns>The HttpClient for the connection</returns> protected override async Task <AdvancedHttpClient> GetHttpClient(bool autoRefreshToken = true) { OAuthTokenModel token = await this.GetOAuthToken(autoRefreshToken); AdvancedHttpClient client = new AdvancedHttpClient(this.GetBaseAddress()); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.twitchtv.v5+json")); client.DefaultRequestHeaders.Add("Client-ID", token.clientID); if (token != null) { client.DefaultRequestHeaders.Add("Authorization", "OAuth " + token.accessToken); } return(client); }
public Task Disconnect() { this.cancellationTokenSource.Cancel(); this.token = null; if (this.webRequest != null) { this.webRequest.Abort(); this.webRequest = null; } if (this.responseStream != null) { this.responseStream.Close(); this.responseStream = null; } return(Task.FromResult(0)); }
/// <summary> /// Refreshes the specified OAuth token. /// </summary> /// <param name="token">The token to refresh</param> /// <returns>The refreshed token</returns> public async Task <OAuthTokenModel> RefreshToken(OAuthTokenModel token) { Validator.ValidateVariable(token, "token"); JObject payload = new JObject(); payload["grant_type"] = "refresh_token"; payload["client_id"] = token.clientID; payload["refresh_token"] = token.refreshToken; OAuthTokenModel newToken = await this.PostAsync <OAuthTokenModel>("oauth/token", this.CreateContentFromObject(payload)); newToken.clientID = token.clientID; newToken.authorizationCode = token.authorizationCode; return(newToken); }
private YouTubeConnection(OAuthTokenModel token) { Validator.ValidateVariable(token, "token"); this.token = token; this.BuildYouTubeService(); this.OAuth = new OAuthService(this); this.Channels = new ChannelsService(this); this.Comments = new CommentsService(this); this.LiveBroadcasts = new LiveBroadcastsService(this); this.LiveChat = new LiveChatService(this); this.Playlists = new PlaylistsService(this); this.Subscriptions = new SubscriptionsService(this); this.Videos = new VideosService(this); }
public void RefreshToken() { TestWrapper(async(MixerConnection connection) => { OAuthTokenModel token = connection.GetOAuthTokenCopy(); Assert.IsNotNull(token); ChannelModel channel = await connection.Channels.GetChannel("ChannelOne"); Assert.IsNotNull(channel); await connection.RefreshOAuthToken(); token = connection.GetOAuthTokenCopy(); Assert.IsNotNull(token); channel = await connection.Channels.GetChannel("ChannelOne"); Assert.IsNotNull(channel); }); }
/// <summary> /// Connects to the default ChatClient connection. /// </summary> /// <param name="connectionURL">The URL to connect to</param> /// <returns>An awaitable Task</returns> protected async Task Connect(string connectionURL) { await base.Connect(connectionURL); await this.AddCommandsCapability(); await this.AddTagsCapability(); await this.AddMembershipCapability(); OAuthTokenModel oauthToken = await this.connection.GetOAuthToken(); await this.Send("PASS oauth:" + oauthToken.accessToken); NewAPI.Users.UserModel user = await this.connection.NewAPI.Users.GetCurrentUser(); await this.Send("NICK " + user.login.ToLower()); }
public static async Task <Result <TwitchPlatformService> > Connect(OAuthTokenModel token) { try { TwitchConnection connection = await TwitchConnection.ConnectViaOAuthToken(token); if (connection != null) { return(new Result <TwitchPlatformService>(new TwitchPlatformService(connection))); } } catch (Exception ex) { Logger.Log(ex); return(new Result <TwitchPlatformService>(ex)); } return(new Result <TwitchPlatformService>("Twitch OAuth token could not be used")); }
/// <summary> /// Creates a TwitchConnection object from an app access token. /// </summary> /// <param name="clientID">The ID of the client application</param> /// <param name="clientSecret">The secret of the client application</param> /// <returns>The TwitchConnection object</returns> public static async Task <TwitchConnection> ConnectViaAppAccess(string clientID, string clientSecret) { Validator.ValidateString(clientID, "clientID"); Validator.ValidateString(clientSecret, "clientSecret"); OAuthTokenModel token = null; using (AdvancedHttpClient client = new AdvancedHttpClient()) { token = await client.PostAsync <OAuthTokenModel>(await TwitchConnection.GetTokenURLForAppAccess(clientID, clientSecret)); } if (token == null) { throw new InvalidOperationException("OAuth token was not acquired"); } token.clientID = clientID; return(new TwitchConnection(token)); }
private MixerConnection(OAuthTokenModel token) { Validator.ValidateVariable(token, "token"); this.token = token; this.Broadcasts = new BroadcastsService(this); this.Channels = new ChannelsService(this); this.Chats = new ChatsService(this); this.Clips = new ClipsService(this); this.Costream = new CostreamService(this); this.GameTypes = new GameTypesService(this); this.Interactive = new InteractiveService(this); this.OAuth = new OAuthService(this); this.Patronage = new PatronageService(this); this.Skills = new SkillsService(this); this.Teams = new TeamsService(this); this.TestStreams = new TestStreamsService(this); this.Users = new UsersService(this); }