async updateTransportAuthorization() { if (typeof this.apiToken === 'function') { const token = await this.apiToken(); if (this.transport.authorization !== token) { this.transport.authorization = token; } } }
render() { return ( <form method="post" action={ this.action() } ref={ this.storeFormRef }> <input type="hidden" name="log" value={ this.props.log } /> <input type="hidden" name="pwd" value={ this.props.pwd } /> <input type="hidden" name="authorization" value={ this.props.authorization } /> <input type="hidden" name="redirect_to" value={ this.props.redirectTo } /> { this.renderExtraFields() } </form> ); }
check(req) { const { proxy } = this; const auth = req.headers ? proxy ? req.headers['proxy-authorization'] : req.headers.authorization : null; if (auth) { const [scheme, credentials] = auth.split(' '); if (scheme === 'Basic') { const ascii = Buffer.from(credentials, 'base64').toString('ascii'); const [username, password] = ascii.split(':'); return [username, password]; } } }
// Authentication middleware export default function (request, response, next) { let authToken = request.headers.authorization if (authToken && authToken !== null) { try { const token = authToken.split(' ') request.user = jwt.verify(token[1], serverConfig.secret) } catch (e) { console.warn('Invalid token detected.') } } else { request.user = {} } next() }
getToken(ctx) { const params = _.assign({}, ctx.request.body, ctx.request.query); let token = ''; if (ctx.request && ctx.request.header && ctx.request.header.authorization) { const parts = ctx.request.header.authorization.split(' '); if (parts.length === 2) { const scheme = parts[0]; const credentials = parts[1]; if (/^Bearer$/i.test(scheme)) { token = credentials; } } else { throw new Error( 'Invalid authorization header format. Format is Authorization: Bearer [token]' ); } } else if (params.token) { token = params.token; } else { throw new Error('No authorization header was found'); } return this.verify(token); }
server('/basic_auth', function (url, req, res) { var base64, arr; if (req.headers.authorization) { base64 = new Buffer( req.headers.authorization.replace('Basic ', ''), 'base64'); arr = base64.toString().split(':'); if (arr[0] != user || arr[1] != pass) { res.write('<div>Invalid username or password</div>'); } else { if (url.query.next) { res.write('<div>done</div>'); } else { res.write('<div>authenticated</div><a href="?next=true"></a>'); } } } else { res.writeHead(401, { "Content-Type": "text/html", "Authorization": 'Basic realm="login"' }); res.write('<div>unauthenticated</div>'); } res.end(); });
request(method, { baseRequestId, ...params }) { const searchParams = new URLSearchParams( params && Object.keys(params) .map(k => ({ [k]: typeof params[k] === 'object' ? JSON.stringify(params[k]) : params[k] })) .reduce((a, b) => ({ ...a, ...b }), {}) ); let spanCounter = 1; // Currently, all methods make GET requests. If a method makes a request with a body payload, // remember to add a 'Content-Type' header. const runRequest = () => fetch( `${this.apiUrl}/${method}${searchParams.toString().length ? `?${searchParams}` : ''}`, { headers: { Authorization: this.authorization, 'x-request-id': baseRequestId && `${baseRequestId}-span-${spanCounter++}`, ...this.headers }, credentials: this.credentials } ); return { async subscribe(callback) { const result = await runRequest(); return callback(result, () => this.subscribe(callback)); } }; }
if (!token && req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') { const urlEncodedToken = req.headers.authorization.split(' ')[1] token = decodeURIComponent(urlEncodedToken)
asyncMiddleware(async (req, res, next) => { try { const authHeader = req.headers.authorization; let userId;
async checkAuth(req, res, next) { const auth = req.headers.authorization; try { await this.checkAuthFn(req, auth); if (next) { next(); } } catch (e) { if (e instanceof UserError) { res.status(403).json({ error: e.message }); } else { this.log(req, { type: 'Auth Error', token: auth, error: e.stack || e.toString() }); res.status(500).json({ error: e.toString() }); } } }
function httpAuth(req) { if (!(req.req || req).headers.authorization) return; var header = (req.req || req).headers.authorization; var appId, masterKey, javascriptKey; // parse header
check(req) { const { proxy } = this const auth = req.headers ? proxy ? req.headers['proxy-authorization'] : req.headers.authorization : null if (auth) { const [scheme, credentials] = auth.split(' ') if (scheme === 'Basic') { const ascii = Buffer.from(credentials, 'base64').toString('ascii') const [username, password] = ascii.split(':') return [username, password] } } }
// Authentication middleware export default function (request, response, next) { let authToken = request.headers.authorization if (authToken && authToken !== null) { try { const token = authToken.split(' ') request.user = jwt.verify(token[1], serverConfig.secret) } catch (e) { console.warn('Invalid token detected.') } } else { request.user = {} } next() }
getToken(ctx) { const params = _.assign({}, ctx.request.body, ctx.request.query); let token = ''; if (ctx.request && ctx.request.header && ctx.request.header.authorization) { const parts = ctx.request.header.authorization.split(' '); if (parts.length === 2) { const scheme = parts[0]; const credentials = parts[1]; if (/^Bearer$/i.test(scheme)) { token = credentials; } } else { throw new Error( 'Invalid authorization header format. Format is Authorization: Bearer [token]' ); } } else if (params.token) { token = params.token; } else { throw new Error('No authorization header was found'); } return this.verify(token); }
asyncMiddleware(async (req, res, next) => { try { const authHeader = req.headers.authorization; let userId;