Simple library for getting user OAuth tokens through the implicit grant flow.
This is a simple library that automates the work needed to grab a user-token to use with the Twitch API.
The library is compatible with any and all applications running on C# no matter what other libraries or frameworks you have implemented.
This library will only help you with getting the user to autorize the application and recieve a user token in accordance with the implicit flow.
It will not help you connect to the Twitch API. You will need a separate library, such as TwitchLib for that.
Place the scripts directory anywhere in your project where you can access their namespace with the "using" statement.
In Unity that would be anywhere in your "Assets" folder, in any other project that would simply be your project folder.
Change the variables inside the "ApplicationDetails.cs" file to fit your application.
Un-comment the scopes you need in the "Scopes.cs" file as well.
using VonRiddarn.Twitch.ImplicitOAuth;
// Constructor can be passed an int salt value to get "your own" random randomness.
// Empty constructor defaults to 42.
ImplicitOAuth ioa = new ImplicitOAuth(1234);
string currentState = null;
// This event is triggered when the application recieves a new token and state from the "RequestClientAuthorization" method.
ioa.OnRevcievedValues += Foo;
// This method initialize the flow of getting the token and returns a temporary random state that we will use to check authenticity.
currentState = ioa.RequestClientAuthorization();
private void Foo(string state, string token)
{
if(state != currentState)
{
Console.WriteLine("State does not match up. Possible CSRF attack or other error.");
return;
}
// Don't actually print the user token on screen or to the console.
// Here you should save it where the application can access it whenever it wants to, such as in appdata.
Console.WriteLine($"User Token: {token}");
}
MIT-License.
See the license file for more info.
This script is very loosely based on HellCat's Unity-Twitch-OAuth-Example.
The main difference being that this project uses Implicit Flow, whilst HellCat's uses Authorization Flow.
A lot of help was also recieved in the creation of this library from Kraegon.