-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #556 from Sing-Li/gitlab-oauth
initial implementation of oauth2 client support for gitlab server flow #512
- Loading branch information
Showing
20 changed files
with
233 additions
and
7 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 |
---|---|---|
|
@@ -78,3 +78,4 @@ raix:[email protected] | |
jalik:ufs | ||
jalik:ufs-gridfs | ||
monbro:mongodb-mapreduce-aggregation | ||
accounts-gitlab |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
|
@@ -31,6 +32,7 @@ [email protected] | |
francocatena:[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.build* |
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,3 @@ | ||
# accounts-gitlab | ||
|
||
A login service for Gitlab. Courtesy of the [Rocket.Chat](https://rocket.chat/) open source communications platform. See the [project page](https://www.meteor.com/accounts) on Meteor Accounts for more details. |
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,19 @@ | ||
Accounts.oauth.registerService('gitlab'); | ||
|
||
if (Meteor.isClient) { | ||
Meteor.loginWithGitlab = function(options, callback) { | ||
// support a callback without options | ||
if (! callback && typeof options === "function") { | ||
callback = options; | ||
options = null; | ||
} | ||
|
||
var credentialRequestCompleteCallback = Accounts.oauth.credentialRequestCompleteHandler(callback); | ||
Gitlab.requestCredential(options, credentialRequestCompleteCallback); | ||
}; | ||
} else { | ||
Accounts.addAutopublishFields({ | ||
forLoggedInUser: ['services.gitlab'], | ||
forOtherUsers: ['services.gitlab.username'] | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
Package.describe({ | ||
summary: "Login service for Gitlab accounts", | ||
version: "1.0.5-plugins.0" | ||
}); | ||
|
||
Package.onUse(function(api) { | ||
api.use('accounts-base', ['client', 'server']); | ||
// Export Accounts (etc) to packages using this one. | ||
api.imply('accounts-base', ['client', 'server']); | ||
api.use('accounts-oauth', ['client', 'server']); | ||
api.use('gitlab', ['client', 'server']); | ||
|
||
api.addFiles('gitlab_login_button.css', 'client'); | ||
|
||
api.addFiles("gitlab.js"); | ||
}); |
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 @@ | ||
.build* |
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,7 @@ | ||
# gitlab | ||
|
||
An implementation of the GitLab OAuth2 flow. It works with your own private GitLab server instance. | ||
|
||
This software is supplied courtesy of the [Rocket.Chat](https://rocket.chat/) open source communications platform. | ||
|
||
See the [project page](https://www.meteor.com/accounts) on Meteor Accounts for more details. |
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,38 @@ | ||
// Request Gitlab credentials for the user | ||
// @param options {optional} | ||
// @param credentialRequestCompleteCallback {Function} Callback function to call on | ||
// completion. Takes one argument, credentialToken on success, or Error on | ||
// error. | ||
Gitlab.requestCredential = function (options, credentialRequestCompleteCallback) { | ||
// support both (options, callback) and (callback). | ||
if (!credentialRequestCompleteCallback && typeof options === 'function') { | ||
credentialRequestCompleteCallback = options; | ||
options = {}; | ||
} | ||
|
||
var config = ServiceConfiguration.configurations.findOne({service: 'gitlab'}); | ||
if (!config) { | ||
credentialRequestCompleteCallback && credentialRequestCompleteCallback( | ||
new ServiceConfiguration.ConfigError()); | ||
return; | ||
} | ||
|
||
var credentialToken = Random.secret(); | ||
var loginStyle = OAuth._loginStyle('gitlab', config, options); | ||
|
||
var loginUrl = | ||
Gitlab.ServerURL + '/oauth/authorize' + | ||
'?client_id=' + config.clientId + | ||
'&redirect_uri=' + OAuth._redirectUri('gitlab', config) + | ||
'&response_type=code' + | ||
'&state=' + OAuth._stateParam(loginStyle, credentialToken, options.redirectUrl); | ||
|
||
OAuth.launchLogin({ | ||
loginService: "gitlab", | ||
loginStyle: loginStyle, | ||
loginUrl: loginUrl, | ||
credentialRequestCompleteCallback: credentialRequestCompleteCallback, | ||
credentialToken: credentialToken, | ||
popupOptions: {width: 900, height: 450} | ||
}); | ||
}; |
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,3 @@ | ||
Gitlab = {}; | ||
|
||
Gitlab.ServerURL = 'http://corei3:3000'; // this needs to be configured from Settings |
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,14 @@ | ||
<template name="configureLoginServiceDialogForGitlab"> | ||
<p> | ||
First, you'll need to get a Gitlab Client ID. Follow these steps: | ||
</p> | ||
<ol> | ||
<li> | ||
Visit <a href="http://corei3:3000/oauth/applications/new" target="blank">http://corei3:3000/oauth/applications/new</a> | ||
</li> | ||
|
||
<li> | ||
Set Authorization callback URL to: <span class="url">{{siteUrl}}_oauth/gitlab</span> | ||
</li> | ||
</ol> | ||
</template> |
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,12 @@ | ||
Template.configureLoginServiceDialogForGitlab.helpers({ | ||
siteUrl: function () { | ||
return Meteor.absoluteUrl(); | ||
} | ||
}); | ||
|
||
Template.configureLoginServiceDialogForGitlab.fields = function () { | ||
return [ | ||
{property: 'clientId', label: 'Client ID'}, | ||
{property: 'secret', label: 'Client Secret'} | ||
]; | ||
}; |
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,77 @@ | ||
OAuth.registerService('gitlab', 2, null, function(query) { | ||
|
||
var accessToken = getAccessToken(query); | ||
console.log('at: ' + accessToken); | ||
var identity = getIdentity(accessToken); | ||
console.log('id: ' + JSON.stringify(identity)); | ||
var primaryEmail = identity.email; | ||
console.log('primay: ' + JSON.stringify(primaryEmail)); | ||
|
||
return { | ||
serviceData: { | ||
id: identity.id, | ||
accessToken: OAuth.sealSecret(accessToken), | ||
email: identity.email || '', | ||
username: identity.username, | ||
emails: [identity.email] | ||
}, | ||
options: {profile: {name: identity.username}} | ||
}; | ||
}); | ||
|
||
|
||
var userAgent = "Meteor"; | ||
if (Meteor.release) | ||
userAgent += "/" + Meteor.release; | ||
|
||
var getAccessToken = function (query) { | ||
var config = ServiceConfiguration.configurations.findOne({service: 'gitlab'}); | ||
if (!config) | ||
throw new ServiceConfiguration.ConfigError(); | ||
|
||
|
||
var response; | ||
try { | ||
response = HTTP.post( | ||
Gitlab.ServerURL + "/oauth/token", { | ||
headers: { | ||
Accept: 'application/json', | ||
"User-Agent": userAgent | ||
}, | ||
params: { | ||
code: query.code, | ||
client_id: config.clientId, | ||
client_secret: OAuth.openSecret(config.secret), | ||
redirect_uri: OAuth._redirectUri('gitlab', config), | ||
grant_type: 'authorization_code', | ||
state: query.state | ||
} | ||
}); | ||
} catch (err) { | ||
throw _.extend(new Error("Failed to complete OAuth handshake with Gitlab. " + err.message), | ||
{response: err.response}); | ||
} | ||
if (response.data.error) { // if the http response was a json object with an error attribute | ||
throw new Error("Failed to complete OAuth handshake with Gitlab. " + response.data.error); | ||
} else { | ||
return response.data.access_token; | ||
} | ||
}; | ||
|
||
var getIdentity = function (accessToken) { | ||
try { | ||
return HTTP.get( | ||
Gitlab.ServerURL + "/api/v3/user", { | ||
headers: {"User-Agent": userAgent}, // http://doc.gitlab.com/ce/api/users.html#Current-user | ||
params: {access_token: accessToken} | ||
}).data; | ||
} catch (err) { | ||
throw _.extend(new Error("Failed to fetch identity from Gitlab. " + err.message), | ||
{response: err.response}); | ||
} | ||
}; | ||
|
||
|
||
Gitlab.retrieveCredential = function(credentialToken, credentialSecret) { | ||
return OAuth.retrieveCredential(credentialToken, credentialSecret); | ||
}; |
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,23 @@ | ||
Package.describe({ | ||
summary: "Gitlab OAuth flow", | ||
version: "1.1.4-plugins.0" | ||
}); | ||
|
||
Package.onUse(function(api) { | ||
api.use('oauth2', ['client', 'server']); | ||
api.use('oauth', ['client', 'server']); | ||
api.use('http', ['server']); | ||
api.use('underscore', 'client'); | ||
api.use('templating', 'client'); | ||
api.use('random', 'client'); | ||
api.use('service-configuration', ['client', 'server']); | ||
|
||
api.export('Gitlab'); | ||
|
||
api.addFiles( | ||
['gitlab_configure.html', 'gitlab_configure.js'], | ||
'client'); | ||
|
||
api.addFiles(['gitlab_common.js','gitlab_server.js'], 'server'); | ||
api.addFiles(['gitlab_common.js','gitlab_client.js'], 'client'); | ||
}); |
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