Giter Club home page Giter Club logo

twitchimplicitoauth's Introduction

TwitchImplicitOAuth

Simple library for getting user OAuth tokens through the implicit grant flow.

About

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.

How To use

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

License

MIT-License.
See the license file for more info.

Special thanks

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.

twitchimplicitoauth's People

Contributors

vonriddarn avatar shadowfied avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.