This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue TryGhost/Ghost#7452, requires TryGhost/Ghost#7451 - use a `ghostOAuth` config flag to switch between the old-style per-install auth and centralized OAuth auth based on config provided by the server - add OAuth flows for: - setup - sign-in - sign-up - re-authenticate - add custom `oauth-ghost` authenticator to support our custom data structure - add test helpers to stub successful/failed oauth authentication - hide change password form if using OAuth (temporary - a way to change password via oauth provider will be added later)
- Loading branch information
1 parent
7385c26
commit 0a163d7
Showing
28 changed files
with
1,003 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */ | ||
import Oauth2Authenticator from './oauth2'; | ||
import computed from 'ember-computed'; | ||
import RSVP from 'rsvp'; | ||
import run from 'ember-runloop'; | ||
import {assign} from 'ember-platform'; | ||
import {isEmpty} from 'ember-utils'; | ||
import {wrap} from 'ember-array/utils'; | ||
|
||
export default Oauth2Authenticator.extend({ | ||
serverTokenEndpoint: computed('ghostPaths.apiRoot', function () { | ||
return `${this.get('ghostPaths.apiRoot')}/authentication/ghost`; | ||
}), | ||
|
||
// TODO: all this is doing is changing the `data` structure, we should | ||
// probably create our own token auth, maybe look at | ||
// https://github.com/jpadilla/ember-simple-auth-token | ||
authenticate(identification, password, scope = []) { | ||
return new RSVP.Promise((resolve, reject) => { | ||
// const data = { 'grant_type': 'password', username: identification, password }; | ||
let data = identification; | ||
let serverTokenEndpoint = this.get('serverTokenEndpoint'); | ||
let scopesString = wrap(scope).join(' '); | ||
if (!isEmpty(scopesString)) { | ||
data.scope = scopesString; | ||
} | ||
this.makeRequest(serverTokenEndpoint, data).then((response) => { | ||
run(() => { | ||
let expiresAt = this._absolutizeExpirationTime(response.expires_in); | ||
this._scheduleAccessTokenRefresh(response.expires_in, expiresAt, response.refresh_token); | ||
if (!isEmpty(expiresAt)) { | ||
response = assign(response, {'expires_at': expiresAt}); | ||
} | ||
resolve(response); | ||
}); | ||
}, (xhr) => { | ||
run(null, reject, xhr.responseJSON || xhr.responseText); | ||
}); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.