Skip to content

Instantly share code, notes, and snippets.

View jesster2k10's full-sized avatar
🏠
Working from home

Jesse Onolememen jesster2k10

🏠
Working from home
View GitHub Profile
@jesster2k10
jesster2k10 / README.md
Last active April 25, 2024 00:54
JWT Auth + Refresh Tokens in Rails

JWT Auth + Refresh Tokens in Rails

This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.

I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)

Before trying it out DIY, I considered using:

@jesster2k10
jesster2k10 / README.md
Last active October 29, 2023 07:37
Rails API Social Login

Rails API-Only Social Login

This is another piece of code I've extrapolated from a Ruby on Rails project I'm currently working on. The code implmenets social login with a RoR API-based application, targeted at API clients.

The setup does not involve any browser-redirects or sessions as you would have to use working with Omniauth. Instead, what it does is takes an access_token generated on client-side SDKs, retireves user info from the access token and creates a new user and Identity in the database.

This setup works with native applications as described in the Google iOS Sign In Docs (see Authenticating with a backend server)

@jesster2k10
jesster2k10 / Activity.ts
Last active August 27, 2023 11:10
Node.js Social Activity Stream
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToOne,
BaseEntity,
} from 'typeorm'
import { Profile } from 'entities'
import { ActivityTargetType, ActivityVerb } from './enums'
@jesster2k10
jesster2k10 / base_provider_spec.rb
Created April 26, 2020 15:17
Social Login Specs
require 'rails_helper'
RSpec.describe External::Provider::Base do
let(:subject) { described_class.new SecureRandom.hex }
describe '#for' do
it 'returns Facebook provider' do
class_instance = described_class.for :facebook
expect(class_instance).to eq(External::Provider::Facebook)
end
const routes: any[] = [
{
path: 'account',
component: <AccountStep />,
requiredFields: ['email', 'first_name', 'last_name', 'password']
},
{
path: 'profile',
component: <ProfileStep />,
requiredFields: ['user.occupation']
@jesster2k10
jesster2k10 / Fade.tsx
Created July 4, 2019 20:52
React Native iOS 11 Style Large Title with Support For Search Component & Menu Buttons
import React, { Component } from 'react'
import { Animated, StyleProp, ViewStyle } from 'react-native'
export type FadeDirection = 'up' | 'down'
interface FadeProps {
visible?: boolean
style?: StyleProp<ViewStyle>
children: React.ReactNode
direction?: FadeDirection
@jesster2k10
jesster2k10 / deviceSize.ts
Created April 13, 2020 21:00
React Native Device Size
import {Dimensions, Platform} from 'react-native'
const window = Dimensions.get('window')
const {width, height} = window
type DeviceSize =
| 'xsmall'
| 'small'
| 'normal'
| 'large'