Skip to content

neam/auth0-mock-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Auth0 Mock API

A simple mock api for Auth0 to enable offline local development. To install, run:

npm -g install api-mock
git clone https://github.com/neam/auth0-mock-api.git auth0-mock-api
cd auth0-mock-api
openssl genrsa -des3 -out server.key 1024 # any passphrase will do
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

To start the local mock server:

api-mock auth0-mock-api-blueprint.md --port 2999 --ssl-port 3000 --ssl-enable --cors-disable false

The local api is then available on https://127.0.0.1:3000/

Note: First time, you need to visit https://127.0.0.1:3000/tokeninfo an accept the self-signed certificate in each browser that you will be using the mock api.

To use this with auth0-angular, use the following settings in .config():

authProvider.init({
    domain: '127.0.0.1:3000',
    clientID: 'auth0mockapiclientid',
    ...
});
window.auth0mockdata = {
    profile: {"name":"John Doe","given_name":"John","family_name":"Doe","gender":"male","picture":"http://placehold.it/150x150","age_range":{"min":21},"devices":[{"hardware":"iPhone","os":"iOS"}],"updated_time":"2015-09-07T08:55:46+0000","installed":true,"is_verified":false,"locale":"en_US","name_format":"{first} {last}","verified":true,"nickname":"auth0mockapi","user_metadata":{"api_endpoints":[{"slug":"local"}],"default_api_endpoint_slug":"local","original_mixpanel_distinct_id":"mock-original_mixpanel_distinct_id","signup_tracked":true},"email":"[email protected]","app_metadata":{"r0":{"permissions":{"example":{"superuser":0,"groups":[]}}}},"email_verified":true,"clientID":"foobar","updated_at":"2015-09-09T07:25:39.429Z","user_id":"auth0mockapi|123123123123123123","identities":[{"access_token":"foobar","provider":"auth0mockapi","user_id":"123123123123123123","connection":"auth0mockapi","isSocial":true}],"created_at":"2015-09-03T10:10:43.432Z","global_client_id":"foobar"},
    idToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJnaXZlbl9uYW1lIjoiSm9obiIsImZhbWlseV9uYW1lIj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IzMTIzMTIzMTIzIiwiY29ubmVjdGlvbiI6ImF1dGgwbW9ja2FwaSIsImlzU29jaWFsIjp0cnVlfV0sImNyZWF0ZWRfYXQiOiIyMDE1LTA5LTAzVDEwOjEwOjQzLjQzMloiLCJnbG9iYWxfY2xpZW50X2lkIjoiZm9vYmFyIn0._HkQuZs6Y6N38biAnksnWg3Ayf3qnE2hwBkeMKfxbiE'
};

Then in auth0-angular.js, replace signinCall(options); with the following:

// Auto-sign-in with fake profile data
successFn(window.auth0mockdata.profile, window.auth0mockdata.idToken, 'accessToken-foo', 'state-foo');
//signinCall(options);

All signins will then be successful without any actual external signin process taking place.

Mock API documentation is available on http://docs.auth0mockapi.apiary.io/

Happy offline dev :)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published