All Projects → symfonycorp → Connect

symfonycorp / Connect

Licence: mit
The SymfonyConnect official API SDK

Projects that are alternatives of or similar to Connect

Hwioauthbundle
OAuth client integration for Symfony. Supports both OAuth1.0a and OAuth2.
Stars: ✭ 2,150 (+2400%)
Mutual labels:  symfony, authentication, oauth
Fosite
Extensible security first OAuth 2.0 and OpenID Connect SDK for Go.
Stars: ✭ 1,738 (+1920.93%)
Mutual labels:  sdk, authentication, oauth
Auth0.js
Auth0 headless browser sdk
Stars: ✭ 755 (+777.91%)
Mutual labels:  sdk, authentication
Cpprestsdk
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Stars: ✭ 6,631 (+7610.47%)
Mutual labels:  sdk, oauth
Play Silhouette
Silhouette is an authentication library for Play Framework applications that supports several authentication methods, including OAuth1, OAuth2, OpenID, CAS, 2FA, TOTP, Credentials, Basic Authentication or custom authentication schemes.
Stars: ✭ 826 (+860.47%)
Mutual labels:  authentication, oauth
Doorkeeper
Doorkeeper is an OAuth 2 provider for Ruby on Rails / Grape.
Stars: ✭ 4,917 (+5617.44%)
Mutual labels:  authentication, oauth
Swiftinstagram
Instagram API client written in Swift
Stars: ✭ 570 (+562.79%)
Mutual labels:  sdk, authentication
Play Authenticate
An authentication plugin for Play Framework 2.x (Java)
Stars: ✭ 813 (+845.35%)
Mutual labels:  authentication, oauth
Angular Token
🔑 Token based authentication service for Angular with interceptor and multi-user support. Works best with devise token auth for Rails. Example:
Stars: ✭ 376 (+337.21%)
Mutual labels:  authentication, oauth
Google Auth Library Nodejs
🔑 Google Auth Library for Node.js
Stars: ✭ 1,094 (+1172.09%)
Mutual labels:  authentication, oauth
Visa
Easy third party authentication (OAuth 2.0) for Flutter apps.
Stars: ✭ 50 (-41.86%)
Mutual labels:  authentication, oauth
Ueberauth
An Elixir Authentication System for Plug-based Web Applications
Stars: ✭ 1,259 (+1363.95%)
Mutual labels:  authentication, oauth
Buji Pac4j
pac4j security library for Shiro: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 444 (+416.28%)
Mutual labels:  authentication, oauth
Retroauth
A library build on top of retrofit, for simple handling of authenticated requests
Stars: ✭ 405 (+370.93%)
Mutual labels:  authentication, oauth
Next Auth
Authentication for Next.js
Stars: ✭ 8,362 (+9623.26%)
Mutual labels:  authentication, oauth
Play Pac4j
Security library for Play framework 2 in Java and Scala: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 375 (+336.05%)
Mutual labels:  authentication, oauth
Pizzly
The simplest, fastest way to integrate your app with an OAuth API 😋
Stars: ✭ 796 (+825.58%)
Mutual labels:  authentication, oauth
Stormpath Sdk Php
PHP SDK for the Stormpath User Management and Authentication REST+JSON API
Stars: ✭ 72 (-16.28%)
Mutual labels:  authentication, oauth
Express Stormpath
Build simple, secure web applications with Stormpath and Express!
Stars: ✭ 327 (+280.23%)
Mutual labels:  authentication, oauth
Oauth
🔗 OAuth 2.0 implementation for various providers in one place.
Stars: ✭ 336 (+290.7%)
Mutual labels:  authentication, oauth

SymfonyConnect SDK

About

This is the official SDK for the SymfonyConnect API. It works for the public API or with a registered OAuth application. To register an application, please go to your SymfonyConnect Account.

Installation

To install the SDK, run the command below and you will get the latest version:

composer require symfonycorp/connect

Usage

OAuth

To use the SDK in a Symfony application, we recommend using the built-in bundle.

Otherwise, you can take inspiration from the following part, which will show you how to include OAuth authentication within a Silex App.

Warning: We take for granted that you already have registered your app on SymfonyConnect and that you're in possession of your application_id, application_secret and scope.

  1. Configure your silex app with the data we gave us at app registration.

    // index.php
    use SymfonyCorp\Connect\Api\Api;
    use SymfonyCorp\Connect\OAuthConsumer;
    
    $app = new Silex\Application();
    $app['connect_id'] = 'application_id';
    $app->register(new Silex\Provider\UrlGeneratorServiceProvider());
    $app->register(new Silex\Provider\SessionServiceProvider());
    
    $app['connect_secret'] = 'application_secret';
    // List of scope copy-pasted from your application page on SymfonyConnect
    $app['connect_scope'] = array(
        'SCOPE_ADDITIONAL_EMAILS',
        'SCOPE_BIRTHDAY',
        'SCOPE_EMAIL',
        'SCOPE_LOCATION',
        'SCOPE_PUBLIC',
        'SCOPE_SSH_KEYS',
    );
    
    $app['connect_consumer'] = new OAuthConsumer(
        $app['connect_id'],
        $app['connect_secret'],
        implode(' ', $app['connect_scope']) // scope MUST be space separated
    );
    $app['connect_api'] = new Api();
    

    This done. We can now move on to the second step.

  2. We need to create two controllers to handle the OAuth2 Three-Legged workflow.

    The first controller goal is to redirect the user to SymfonyConnect in order to ask him for the authorization that your app will use his data. This controller will be bound to the connect_auth route. In your template, you'll need to create a link to this route.

    // index.php
    $app->get('/connect/new', function () use ($app) {
        $callback = $app['url_generator']->generate('connect_callback', array(), true);
        $url = $app['connect_consumer']->getAuthorizationUri($callback);
    
        return $app->redirect($url);
    })->bind('connect_auth');
    

    The second controller is the one that will welcome the user after SymfonyConnect redirected him to your application. When registering your client, you'll have to provide the exact absolute URL that points to this controller.

    $app->get('/connect/callback', function (Request $request) use ($app) {
        // There was an error during the workflow.
        if ($request->get('error')) {
            throw new \RuntimeException($request->get('error_description'));
        }
    
        // Everything went fine, you can now request an access token.
        try {
            $data = $app['connect_consumer']->requestAccessToken($app['url_generator']->generate('connect_callback', array(), true), $request->get('code'));
        } catch (OAuthException $e) {
            throw $e;
        }
    
        // At this point, we have an access token and we can use the SDK to request the API
        $app['connect_api']->setAccessToken($data['access_token']); // All further request will be done with this access token
        $root = $app['connect_api']->getRoot();
        $user = $root->getCurrentUser();
        $user->getBadges()->refresh();
    
        $app['session']->start();
        $app['session']->set('connect_access_token', $data['access_token']);
        $app['session']->set('connect_user', $user);
    
        return $app->redirect('/');
    })->bind('connect_callback');
    
  3. Create a link from your template

    In a template, you can use the following snippet of code to render a SymfonyConnect button:

    <a href="#" class="connect-with-symfony">
        <span>Log in with SymfonyConnect</span>
    </a>
    

    And include the following CSS file: https://connect.symfony.com/css/sln.css

Et voilà! Your application can now use SymfonyConnect as an authentication method!

The API

The SymfonyConnect Connect API is RESTFul and (tries to) conforms to the HATEOAS principle.

Here are some useful recipes.

  1. Search

    $root = $api->getRoot();
    
    // Will search for users
    $users = $root->getUsers('fab');
    
  2. Edit authenticated user

    $app['connect_api']->setAccessToken($app['session']->get('connect_access_token'));
    $root = $app['connect_api']->getRoot();
    $user = $root->getCurrentUser();
    $user->setBiography("I'm sexy and I know it.");
    $user->submitForm();
    

As you can see by these examples, you always have to to go through the API Root to make an action. This is because the API is discoverable and that the SDK should not know anything beside the API's entry point.

License

This library is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].