netlify-graph-auth
Advanced tools
Comparing version 0.0.1-beta.2 to 0.0.1-beta.3
@@ -7,3 +7,3 @@ import type { Storage } from './storage'; | ||
graphOrigin?: string; | ||
appId: string; | ||
siteId: string; | ||
oauthFinishOrigin?: string; | ||
@@ -73,3 +73,3 @@ oauthFinishPath?: string; | ||
graphOrigin: string; | ||
appId: string; | ||
siteId: string; | ||
_storageKey: string; | ||
@@ -76,0 +76,0 @@ _storage: Storage; |
@@ -301,3 +301,3 @@ "use strict"; | ||
} | ||
function exchangeCode(graphOrigin, appId, redirectOrigin, redirectPath, code, token, verifier) { | ||
function exchangeCode(graphOrigin, siteId, redirectOrigin, redirectPath, code, token, verifier) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -313,3 +313,3 @@ var redirectUri, url, headers, response; | ||
query: { | ||
app_id: appId, | ||
app_id: siteId, | ||
redirect_uri: redirectUri, | ||
@@ -339,3 +339,3 @@ code: code, | ||
} | ||
function exchangeRefreshToken(graphOrigin, appId, refreshToken) { | ||
function exchangeRefreshToken(graphOrigin, siteId, refreshToken) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -350,3 +350,3 @@ var url, headers, response; | ||
query: { | ||
app_id: appId, | ||
app_id: siteId, | ||
}, | ||
@@ -383,4 +383,4 @@ }); | ||
} | ||
function tokenFromStorage(storage, appId) { | ||
var v = storage.getItem(appId); | ||
function tokenFromStorage(storage, siteId) { | ||
var v = storage.getItem(siteId); | ||
if (v) { | ||
@@ -449,3 +449,3 @@ var possibleToken = JSON.parse(v); | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, exchangeRefreshToken(this.graphOrigin, this.appId, refreshToken)]; | ||
case 0: return [4 /*yield*/, exchangeRefreshToken(this.graphOrigin, this.siteId, refreshToken)]; | ||
case 1: | ||
@@ -505,3 +505,3 @@ baseResponse = _a.sent(); | ||
challenge = _a.sent(); | ||
query = __assign({ service: service, app_id: this.appId, response_type: 'code', redirect_origin: this._redirectOrigin, redirect_path: this._redirectPath, communication_mode: this._communicationMode, code_challenge: challenge.challenge, code_challenge_method: challenge.method, state: stateParam }, (scopes ? { scopes: scopes.join(',') } : {})); | ||
query = __assign({ service: service, app_id: this.siteId, response_type: 'code', redirect_origin: this._redirectOrigin, redirect_path: this._redirectPath, communication_mode: this._communicationMode, code_challenge: challenge.challenge, code_challenge_method: challenge.method, state: stateParam }, (scopes ? { scopes: scopes.join(',') } : {})); | ||
if (useTestFlow) { | ||
@@ -550,3 +550,3 @@ query.test = 'true'; | ||
else { | ||
exchangeCode(_this.graphOrigin, _this.appId, _this._redirectOrigin, _this._redirectPath, code, _this._accessToken, verifier) | ||
exchangeCode(_this.graphOrigin, _this.siteId, _this._redirectOrigin, _this._redirectPath, code, _this._accessToken, verifier) | ||
.then(function (baseResponse) { | ||
@@ -608,3 +608,3 @@ var errorResponse = baseResponse; | ||
else { | ||
exchangeCode(_this.graphOrigin, _this.appId, _this._redirectOrigin, _this._redirectPath, code, _this._accessToken, verifier) | ||
exchangeCode(_this.graphOrigin, _this.siteId, _this._redirectOrigin, _this._redirectPath, code, _this._accessToken, verifier) | ||
.then(function (baseResponse) { | ||
@@ -834,5 +834,5 @@ var errorResponse = baseResponse; | ||
this.findMissingAuthServices = helpers_1.findMissingAuthServices; | ||
var appId = opts.appId, oauthFinishOrigin = opts.oauthFinishOrigin, oauthFinishPath = opts.oauthFinishPath; | ||
var siteId = opts.siteId, oauthFinishOrigin = opts.oauthFinishOrigin, oauthFinishPath = opts.oauthFinishPath; | ||
this.graphOrigin = opts.graphOrigin || DEFAULT_GRAPH_ORIGIN; | ||
this.appId = appId; | ||
this.siteId = siteId; | ||
var windowUri = uri_1.default.parse(window.location.toString()); | ||
@@ -846,4 +846,4 @@ this._redirectOrigin = normalizeRedirectOrigin(oauthFinishOrigin || windowUri.origin); | ||
origin: opts.graphOrigin || DEFAULT_GRAPH_ORIGIN, | ||
path: '/dynamic', | ||
query: { app_id: appId }, | ||
path: '/graphql', | ||
query: { app_id: siteId }, | ||
}); | ||
@@ -854,3 +854,3 @@ this._fetchUrl = opts.graphqlUrl || uri_1.default.toString(fetchUrl); | ||
((0, storage_1.hasLocalStorage)() ? new storage_1.LocalStorage() : new storage_1.InMemoryStorage()); | ||
this._storageKey = this.appId; | ||
this._storageKey = this.siteId; | ||
this._accessToken = tokenFromStorage(this._storage, this._storageKey); | ||
@@ -857,0 +857,0 @@ this._communicationMode = opts.communicationMode || 'post_message'; |
{ | ||
"name": "netlify-graph-auth", | ||
"version": "0.0.1-beta.2", | ||
"version": "0.0.1-beta.3", | ||
"description": "Client-side authentication for Netlify GraphQL APIs", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -19,12 +19,10 @@ # Netlify Graph Authentication Helpers for browsers | ||
First, we'll construct a new NetlifyGraphAuth instance. It requires the | ||
name of the service and an appId. | ||
First, we'll construct a new NetlifyGraphAuth instance with our siteId. | ||
```javascript | ||
import NetlifyGraphAuth from 'netlify-graph-auth'; | ||
import process from 'process'; | ||
const APP_ID = YOUR_APP_ID; | ||
const auth = new NetlifyGraphAuth({ | ||
appId: APP_ID, | ||
siteId: process.env.SITE_ID, | ||
}); | ||
@@ -42,9 +40,8 @@ ``` | ||
```javascript | ||
auth.isLoggedIn('github').then(isLoggedIn => { | ||
if (isLoggedIn) { | ||
console.log('Already logged in to GitHub'); | ||
} else { | ||
console.log('Not logged in to GitHub.'); | ||
} | ||
}); | ||
const isLoggedIn = await auth.isLoggedIn('github'); | ||
if (isLoggedIn) { | ||
console.log('Already logged in to GitHub'); | ||
} else { | ||
console.log('Not logged in to GitHub.'); | ||
} | ||
``` | ||
@@ -62,14 +59,17 @@ | ||
```javascript | ||
auth | ||
.login('github') | ||
.then(() => { | ||
auth.isLoggedIn('github').then(isLoggedIn => { | ||
if (isLoggedIn) { | ||
console.log('Successfully logged in to GitHub'); | ||
} else { | ||
console.log('Did not grant auth for GitHub'); | ||
} | ||
}); | ||
}) | ||
.catch(e => console.error('Problem logging in', e)); | ||
try { | ||
// Prompt the user to log into GitHub | ||
await auth.login('github'); | ||
// Check to see if they logged in successfully | ||
const isLoggedIn = await auth.isLoggedIn('github'); | ||
if (isLoggedIn) { | ||
console.log('Successfully logged in to GitHub'); | ||
} else { | ||
console.log('Did not grant auth for GitHub'); | ||
} | ||
} catch (error) { | ||
console.error('Problem logging in', error); | ||
} | ||
``` | ||
@@ -85,3 +85,4 @@ | ||
```javascript | ||
auth.logout('github').then(response => { | ||
const response = await auth.logout('github'); | ||
if (response.result === 'success') { | ||
@@ -92,3 +93,2 @@ console.log('Logout succeeded'); | ||
} | ||
}); | ||
``` |
Sorry, the diff of this file is not supported yet
89053