Skip to content

auth0-blog/relay-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Relay Auth

This is the code for Auth0's Relay tutorial. It shows how to set up a simple Relay app that reads data from a GraphQL endpoint. It also shows how to optionally add authentication middleware to the endpoint and how to send JWTs to it for access.

This sample is based off of Michael Hart's simple-relay-starter repo.

Installation

npm install
npm run dev

Authentication

The /graphql endpoint is protected with express-jwt middlware.

// server.js

var authenticate = jwt({
  secret: new Buffer(process.env.AUTH0_CLIENT_SECRET, 'base64'),
  audience: process.env.AUTH0_CLIENT_ID
});


app.use('/graphql', authenticate, graphqlHttp({schema: schema}));

You can send a JWT to the server from the front end using Relay's network layer.

// ConferenceApp.js

var token = localStorage.getItem('id_token');

Relay.injectNetworkLayer(
 new Relay.DefaultNetworkLayer('http://localhost:3000/graphql', {
   headers: {
     Authorization: 'Bearer ' + token
   }
 })
);

License

MIT

What is Auth0?

Auth0 helps you to:

  • Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont others, or enterprise identity systems like Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider.
  • Add authentication through more traditional username/password databases.
  • Add support for linking different user accounts with the same user.
  • Support for generating signed Json Web Tokens to call your APIs and flow the user identity securely.
  • Analytics of how, when and where users are logging in.
  • Pull data from other sources and add it to the user profile, through JavaScript rules.

Create a Free Auth0 Account

  1. Go to Auth0 and click Sign Up.
  2. Use Google, GitHub or Microsoft Account to login.

About

Code sample of the Auth0 Relay tutorial

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published