Initial import from local backup (Documents-Playground/pakerpale)

This commit is contained in:
jeonghwa
2026-07-03 05:27:31 +09:00
commit 3a8de01ba0
1794 changed files with 137027 additions and 0 deletions

View File

@@ -0,0 +1,118 @@
var errors = require('./errors'),
url = require('url');
function buildAuthorizationUri(context, expiresIn, code, token) {
var redirect = url.parse(context.redirect_uri, true);
delete redirect.search;
if (context.scope) {
redirect.query.scope = context.scope.join(',');
}
if (context.state) {
redirect.query.state = context.state;
}
if (expiresIn) {
redirect.query.expires_in = expiresIn;
}
if (code) {
redirect.query.code = code;
}
if (token) {
redirect.query.access_token = token;
redirect.query.token_type = 'Bearer';
}
return url.format(redirect);
}
function authorizeRequestWithClient(authServer, client, context, accountId, callback) {
if (!client) {
return callback(errors.invalidClient(context));
}
if (!context.redirect_uri || !authServer.clientService.isValidRedirectUri(client, context.redirect_uri)) {
return callback(errors.redirectUriMismatch(context));
}
function finalResponse(error, data) {
if(error){
return callback(error);
}
callback(
null,
{
redirectUri: buildAuthorizationUri(context, authServer.expiresIn, data.code, data.access_token),
state: context
}
);
}
if (context.response_type === 'code') {
authServer.tokenService.generateAuthorizationCode(function(error, code){
if(error){
return callback(error);
}
authServer.authorizationService.saveAuthorizationCode({
code: code,
redirectUri: context.redirect_uri,
clientId: client.id,
expiresDate: authServer.getExpiresDate(),
accountId: accountId
}, finalResponse);
});
return;
}
if (context.response_type === 'token') {
authServer.tokenService.generateToken(function(error, token){
if(error){
return callback(error);
}
authServer.authorizationService.saveAccessToken({
clientId: client.id,
access_token: token,
expires_in: authServer.getExpiresDate(),
accountId: accountId,
token_type: 'Bearer'
}, finalResponse);
});
return;
}
callback(errors.invalidResponseType(context.state));
}
function authorizeRequest(context, accountId, callback) {
var authServer = this;
if (!context || !context.response_type) {
return callback(errors.invalidRequest(context));
}
if (context.response_type !== 'token' && context.response_type !== 'code') {
return callback(errors.unsupportedResponseType(context));
}
if (!authServer.isSupportedScope(context.scope)) {
return callback(errors.invalidScope(context));
}
authServer.clientService.getById(context.client_id, function(error, client){
if(error){
return callback(error);
}
authorizeRequestWithClient(authServer, client, context, accountId, callback);
});
}
module.exports = authorizeRequest;

119
node_modules/simple-oauth-server/lib/errors.js generated vendored Normal file
View File

@@ -0,0 +1,119 @@
function invalidRequest(state) {
return {
error: 'invalid_request',
error_description: 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.',
state: state
};
}
function unauthorizedClient(state) {
return {
error: 'unauthorized_client',
error_description: 'The client is not authorized to request an authorization code using this method.',
state: state
};
}
function accessDenied(state) {
return {
error: 'access_denied',
error_description: 'The resource owner or authorization server denied the request.',
state: state
};
}
function unsupportedResponseType(state) {
return {
error: 'unsupported_response_type',
error_description: 'The authorization server does not support obtaining an authorization code using this method.',
state: state
};
}
function redirectUriMismatch(state) {
return {
error: 'invalid_request',
error_description: 'The redirect URI doesn\'t match what is stored for this client',
state: state
};
}
function invalidScope(state) {
return {
error: 'invalid_scope',
error_description: 'The requested scope is invalid, unknown, or malformed.',
state: state
};
}
function invalidResponseType(state) {
return {
error: 'unsupported_response_type',
error_description: 'The authorization server does not support this response type.',
state: state
};
}
function clientCredentialsInvalid(state) {
return {
error: 'unauthorized_client',
error_description: 'The client credentials are invalid.',
state: state
};
}
function userCredentialsInvalid(state) {
return {
error: 'access_denied',
error_description: 'The user credentials are invalid.',
state: state
};
}
function unsupportedGrantType(state) {
return {
error: 'unsupported_grant_type',
error_description: 'The authorization grant type is not supported by the authorization server.',
state: state
};
}
function unsupportedGrantTypeForClient(state) {
return {
error: 'unauthorized_client',
error_description: 'The grant type is not supported for this client.',
state: state
};
}
function invalidAuthorizationCode(state) {
return {
error: 'invalid_grant',
error_description: 'The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.',
state: state
};
}
function invalidClient(state) {
return {
error: 'invalid_client',
error_description: 'Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method).',
state: state
};
}
module.exports = {
invalidRequest: invalidRequest,
unauthorizedClient: unauthorizedClient,
accessDenied: accessDenied,
unsupportedResponseType: unsupportedResponseType,
redirectUriMismatch: redirectUriMismatch,
invalidScope: invalidScope,
invalidResponseType: invalidResponseType,
clientCredentialsInvalid: clientCredentialsInvalid,
userCredentialsInvalid: userCredentialsInvalid,
unsupportedGrantType: unsupportedGrantType,
unsupportedGrantTypeForClient: unsupportedGrantTypeForClient,
invalidAuthorizationCode: invalidAuthorizationCode,
invalidClient: invalidClient
};

View File

@@ -0,0 +1,75 @@
var url = require('url'),
queryString = require('querystring');
function getPostData(request, callback){
if(!request.readable){
//In some circumstances the body has already been
//parsed. Check the commonly used "body" property.
return callback(null, request.body);
}
var data = '';
request.on('data',function(chunk){
if(data.length > (1e6)){
// flood attack, kill.
return request.connection.destroy();
}
data += chunk.toString();
});
request.on('end', function(){
if (data) {
return callback(null, queryString.parse(data));
}
callback();
});
}
function getBearerToken(request) {
if (request && request.headers && request.headers.authorization &&
request.headers.authorization.toLowerCase().indexOf('bearer ') === 0) {
return request.headers.authorization.split(' ').pop();
}
}
function getOauthParameters(callback) {
return function(){
var authServer = this,
args = Array.prototype.slice.call(arguments),
request = args.shift();
getPostData(request, function(error, data){
if(error){
// non error callback but non valid context so OAuth errors will be returned.
return callback(error);
}
if(!data){
data = {};
}
var query = url.parse(request.url, true).query;
for(var key in query){
data[key] = query[key];
}
if(data.scope){
data.scope = data.scope.split(',');
}
if(!data.access_token){
data.access_token = getBearerToken(request);
}
args.unshift(data);
callback.apply(authServer, args);
});
};
}
module.exports = getOauthParameters;

82
node_modules/simple-oauth-server/lib/getTokenData.js generated vendored Normal file
View File

@@ -0,0 +1,82 @@
var errors = require('./errors'),
grantTypes = require('./grantTypes'),
kgo = require('kgo');
function isValidAuthorizationCode(authorizationCode, context) {
return authorizationCode &&
context.code === authorizationCode.code &&
authorizationCode.expiresDate > new Date() &&
'' + context.client_id === '' + authorizationCode.clientId;
}
function getTokenData(context, callback) {
var authServer = this,
tokenData = {
token_type: 'Bearer',
expires_in: authServer.getExpiresDate(),
clientId: context.client_id
};
if (context.grant_type === grantTypes.AUTHORIZATIONCODE) {
authServer.authorizationService.getAuthorizationCode(context.code, function(error, authorizationCode){
if(error){
return callback(error);
}
if(!isValidAuthorizationCode(authorizationCode, context)){
return callback(errors.invalidAuthorizationCode(context));
}
tokenData.accountId = authorizationCode.accountId;
kgo
('token', authServer.tokenService.generateToken)
('refreshToken', authServer.tokenService.generateToken)
('tokenData', ['token', 'refreshToken'], function(token, refreshToken, done){
tokenData.access_token = token;
tokenData.refresh_token = refreshToken;
done(null, tokenData);
})
(['*', 'tokenData'], callback);
});
return;
}
if (context.grant_type === grantTypes.PASSWORD) {
authServer.membershipService.areUserCredentialsValid(context.username, context.password, context.scope, function (error, isValidPassword) {
if(error){
return callback(error);
}
if(!isValidPassword){
return callback(errors.userCredentialsInvalid(context));
}
kgo
('token', authServer.tokenService.generateToken)
('refreshToken', authServer.tokenService.generateToken)
('tokenData', ['token', 'refreshToken'], function(token, refreshToken, done){
tokenData.access_token = token;
tokenData.refresh_token = refreshToken;
done(null, tokenData);
})
(['*', 'tokenData'], callback);
});
return;
}
if (context.grant_type === grantTypes.CLIENTCREDENTIALS) {
kgo
('token', authServer.tokenService.generateToken)
('tokenData', ['token'], function(token, done){
tokenData.access_token = token;
done(null, tokenData);
})
(['*', 'tokenData'], callback);
return;
}
return callback(errors.unsupportedGrantType(context));
}
module.exports = getTokenData;

View File

@@ -0,0 +1,65 @@
var errors = require('./errors'),
getTokenData = require('./getTokenData'),
grantTypes = require('./grantTypes');
function isAllowed(grantType, oauthProvider) {
return grantType === grantTypes.IMPLICIT ||
(grantType === grantTypes.AUTHORIZATIONCODE && oauthProvider.authorizationService) ||
(grantType === grantTypes.CLIENTCREDENTIALS && oauthProvider.clientService) ||
(grantType === grantTypes.PASSWORD && oauthProvider.membershipService) ||
false;
}
function grantAccessToken(context, callback) {
var authServer = this;
if (!context.grant_type) {
return callback(errors.invalidRequest(context));
}
if (!isAllowed(context.grant_type, authServer)) {
return callback(errors.unsupportedGrantType(context));
}
authServer.clientService.getById(context.client_id, function (error, client) {
if(error){
return callback(error);
}
if(!client) {
return callback(errors.invalidClient(context));
}
if(!client.grantTypes || !~client.grantTypes.indexOf(context.grant_type)) {
return callback(errors.unsupportedGrantTypeForClient(context));
}
if(
(
context.grant_type === grantTypes.AUTHORIZATIONCODE ||
context.grant_type === grantTypes.CLIENTCREDENTIALS
) &&
context.client_secret !== client.secret
){
return callback(errors.clientCredentialsInvalid(context));
}
getTokenData.call(authServer, context, function (error, tokenData) {
if(error){
return callback(error);
}
authServer.authorizationService.saveAccessToken(tokenData, function (error, token) {
if(error){
return callback(error);
}
delete token.accountId;
delete token.clientId;
callback(null, token);
});
});
});
}
module.exports = grantAccessToken;

6
node_modules/simple-oauth-server/lib/grantTypes.js generated vendored Normal file
View File

@@ -0,0 +1,6 @@
module.exports = {
PASSWORD: 'password',
IMPLICIT: 'implict',
AUTHORIZATIONCODE: 'authorization_code',
CLIENTCREDENTIALS: 'client_credentials'
};

8
node_modules/simple-oauth-server/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,8 @@
var getOauthParameters = require('./getOauthParameters');
module.exports = {
authorizeRequest: getOauthParameters(require('./authorizeRequest')),
getTokenData: getOauthParameters(require('./getTokenData')),
grantAccessToken: getOauthParameters(require('./grantAccessToken')),
validateAccessToken: getOauthParameters(require('./validateAccessToken'))
};

View File

@@ -0,0 +1,32 @@
function validateAccessToken(context, callback) {
this.authorizationService.getAccessToken(context.access_token, function (error, tokenData) {
if(error){
return callback(error);
}
if (!tokenData || !tokenData.access_token || '' + context.client_id !== '' + tokenData.clientId) {
return callback({
isValid: false,
error: 'Access token not found'
});
}
if (tokenData.expiresDate < new Date()) {
return callback({
isValid: false,
error: 'Access token has expired'
});
}
callback(
null,
{
isValid: true,
accountId: tokenData.accountId,
clientId: tokenData.clientId
}
);
});
}
module.exports = validateAccessToken;