Class: Faker::Omniauth

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/omniauth.rb

Constant Summary

Constants inherited from Base

Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale

Constructor Details

#initialize(name: nil, email: nil) ⇒ Omniauth

Returns a new instance of Omniauth.



11
12
13
14
15
16
17
# File 'lib/faker/default/omniauth.rb', line 11

def initialize(name: nil, email: nil)
  super()

  @name = name || "#{Name.first_name} #{Name.last_name}"
  @email = email || Internet.email(name: self.name)
  @first_name, @last_name = self.name.split
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



6
7
8
# File 'lib/faker/default/omniauth.rb', line 6

def email
  @email
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



6
7
8
# File 'lib/faker/default/omniauth.rb', line 6

def first_name
  @first_name
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



6
7
8
# File 'lib/faker/default/omniauth.rb', line 6

def last_name
  @last_name
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/faker/default/omniauth.rb', line 6

def name
  @name
end

Class Method Details

.apple(name: nil, email: nil, uid: nil) ⇒ Hash

Generate a mock Omniauth response from Apple.

Parameters:

  • name (String) (defaults to: nil)

    A specific name to return in the response.

  • email (String) (defaults to: nil)

    A specific email to return in the response.

  • uid (String) (defaults to: nil)

    A specific UID to return in the response.

Returns:

  • (Hash)

    An auth hash in the format provided by omniauth-apple.

Available since:

  • 2.3.0



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/faker/default/omniauth.rb', line 366

def apple(name: nil, email: nil, uid: nil)
  uid ||= "#{Number.number(digits: 6)}.#{Number.hexadecimal(digits: 32)}.#{Number.number(digits: 4)}"
  auth = Omniauth.new(name: name, email: email)
  {
    provider: 'apple',
    uid: uid,
    info: {
      sub: uid,
      email: auth.email,
      first_name: auth.first_name,
      last_name: auth.last_name
    },
    credentials: {
      token: Crypto.md5,
      refresh_token: Crypto.md5,
      expires_at: Time.forward.to_i,
      expires: true
    },
    extra: {
      raw_info: {
        iss: 'https://appleid.apple.com',
        aud: 'CLIENT_ID',
        exp: Time.forward.to_i,
        iat: Time.forward.to_i,
        sub: uid,
        at_hash: Crypto.md5,
        auth_time: Time.forward.to_i,
        email: auth.email,
        email_verified: true
      }
    }
  }
end

.auth0(name: nil, email: nil, uid: nil) ⇒ Hash

Generate a mock Omniauth response from Auth0.

Parameters:

  • name (String) (defaults to: nil)

    A specific name to return in the response.

  • email (String) (defaults to: nil)

    A specific email to return in the response.

  • uid (String) (defaults to: nil)

    A specific UID to return in the response.

Returns:

  • (Hash)

    An auth hash in the format provided by omniauth-auth0.

Available since:

  • next



410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/faker/default/omniauth.rb', line 410

def auth0(name: nil, email: nil, uid: nil)
  uid ||= "auth0|#{Number.hexadecimal(digits: 24)}"
  auth = Omniauth.new(name: name, email: email)
  {
    provider: 'auth0',
    uid: uid,
    info: {
      name: uid,
      nickname: auth.name,
      email: auth.email,
      image: image
    },
    credentials: {
      expires_at: Time.forward.to_i,
      expires: true,
      token_type: 'Bearer',
      id_token: Crypto.sha256,
      token: Crypto.md5,
      refresh_token: Crypto.md5
    },
    extra: {
      raw_info: {
        email: auth.email,
        email_verified: true,
        iss: 'https://auth0.com/',
        sub: uid,
        aud: 'Auth012345',
        iat: Time.forward.to_i,
        exp: Time.forward.to_i
      }
    }
  }
end

.facebook(name: nil, email: nil, username: nil, uid: Number.number(digits: 7).to_s) ⇒ Hash

Generate a mock Omniauth response from Facebook.

Parameters:

  • name (String) (defaults to: nil)

    A specific name to return in the response.

  • email (String) (defaults to: nil)

    A specific email to return in the response.

  • username (String) (defaults to: nil)

    A specific username to return in the response.

  • uid (String) (defaults to: Number.number(digits: 7).to_s)

    A specific UID to return in the response.

Returns:

  • (Hash)

    An auth hash in the format provided by omniauth-facebook.

Available since:

  • 1.8.0



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/faker/default/omniauth.rb', line 90

def facebook(name: nil, email: nil, username: nil, uid: Number.number(digits: 7).to_s)
  auth = Omniauth.new(name: name, email: email)
  username ||= "#{auth.first_name.downcase[0]}#{auth.last_name.downcase}"
  {
    provider: 'facebook',
    uid: uid,
    info: {
      email: auth.email,
      name: auth.name,
      first_name: auth.first_name,
      last_name: auth.last_name,
      image: image,
      verified: random_boolean
    },
    credentials: {
      token: Crypto.md5,
      expires_at: Time.forward.to_i,
      expires: true
    },
    extra: {
      raw_info: {
        id: uid,
        name: auth.name,
        first_name: auth.first_name,
        last_name: auth.last_name,
        link: "http://www.facebook.com/#{username}",
        username: username,
        location: {
          id: Number.number(digits: 9).to_s,
          name: city_state
        },
        gender: gender,
        email: auth.email,
        timezone: timezone,
        locale: 'en_US',
        verified: random_boolean,
        updated_time: Time.backward.iso8601
      }
    }
  }
end

.github(name: nil, email: nil, uid: Number.number(digits: 8).to_s) ⇒ Hash

Generate a mock Omniauth response from Github.

Parameters:

  • name (String) (defaults to: nil)

    A specific name to return in the response.

  • email (String) (defaults to: nil)

    A specific email to return in the response.

  • uid (String) (defaults to: Number.number(digits: 8).to_s)

    A specific UID to return in the response.

Returns:

  • (Hash)

    An auth hash in the format provided by omniauth-github.

Available since:

  • 1.8.0



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/faker/default/omniauth.rb', line 298

def github(name: nil, email: nil, uid: Number.number(digits: 8).to_s)
  auth = Omniauth.new(name: name, email: email)
   = auth.name.downcase.tr(' ', '-')
  html_url = "https://github.com/#{}"
  api_url = "https://api.github.com/users/#{}"
  {
    provider: 'github',
    uid: uid,
    info: {
      nickname: ,
      email: auth.email,
      name: auth.name,
      image: image,
      urls: {
        GitHub: html_url
      }
    },
    credentials: {
      token: Crypto.md5,
      expires: false
    },
    extra: {
      raw_info: {
        login: ,
        id: uid,
        avatar_url: image,
        gravatar_id: '',
        url: api_url,
        html_url: html_url,
        followers_url: "#{api_url}/followers",
        following_url: "#{api_url}/following{/other_user}",
        gists_url: "#{api_url}/gists{/gist_id}",
        starred_url: "#{api_url}/starred{/owner}{/repo}",
        subscriptions_url: "#{api_url}/subscriptions",
        organizations_url: "#{api_url}/orgs",
        repos_url: "#{api_url}/repos",
        events_url: "#{api_url}/events{/privacy}",
        received_events_url: "#{api_url}/received_events",
        type: 'User',
        site_admin: random_boolean,
        name: auth.name,
        company: nil,
        blog: nil,
        location: city_state,
        email: auth.email,
        hireable: nil,
        bio: nil,
        public_repos: random_number_from_range(1..1000),
        public_gists: random_number_from_range(1..1000),
        followers: random_number_from_range(1..1000),
        following: random_number_from_range(1..1000),
        created_at: Time.backward(days: 36_400).iso8601,
        updated_at: Time.backward(days: 2).iso8601
      }
    }
  }
end

.google(name: nil, email: nil, uid: Number.number(digits: 9).to_s) ⇒ Hash

Generate a mock Omniauth response from Google.

Parameters:

  • name (String) (defaults to: nil)

    A specific name to return in the response.

  • email (String) (defaults to: nil)

    A specific email to return in the response.

  • uid (String) (defaults to: Number.number(digits: 9).to_s)

    A specific UID to return in the response.

Returns:

  • (Hash)

    An auth hash in the format provided by omniauth-google.

Available since:

  • 1.8.0



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/faker/default/omniauth.rb', line 30

def google(name: nil, email: nil, uid: Number.number(digits: 9).to_s)
  auth = Omniauth.new(name: name, email: email)
  {
    provider: 'google_oauth2',
    uid: uid,
    info: {
      name: auth.name,
      first_name: auth.first_name,
      last_name: auth.last_name,
      email: auth.email,
      image: image
    },
    credentials: {
      token: Crypto.md5,
      refresh_token: Crypto.md5,
      expires_at: Time.forward.to_i,
      expires: true
    },
    extra: {
      raw_info: {
        sub: uid,
        email: auth.email,
        email_verified: random_boolean.to_s,
        name: auth.name,
        given_name: auth.first_name,
        family_name: auth.last_name,
        profile: "https://plus.google.com/#{uid}",
        picture: image,
        gender: gender,
        birthday: Date.backward(days: 36_400).strftime('%Y-%m-%d'),
        locale: 'en',
        hd: "#{Company.name.downcase}.com"
      },
      id_info: {
        iss: 'accounts.google.com',
        at_hash: Crypto.md5,
        email_verified: true,
        sub: Number.number(digits: 28).to_s,
        azp: 'APP_ID',
        email: auth.email,
        aud: 'APP_ID',
        iat: Time.forward.to_i,
        exp: Time.forward.to_i,
        openid_id: "https://www.google.com/accounts/o8/id?id=#{uid}"
      }
    }
  }
end

.linkedin(name: nil, email: nil, uid: Number.number(digits: 6).to_s) ⇒ Hash

Generate a mock Omniauth response from LinkedIn.

Parameters:

  • name (String) (defaults to: nil)

    A specific name to return in the response.

  • email (String) (defaults to: nil)

    A specific email to return in the response.

  • uid (String) (defaults to: Number.number(digits: 6).to_s)

    A specific UID to return in the response.

Returns:

  • (Hash)

    An auth hash in the format provided by omniauth-linkedin.

Available since:

  • 1.8.0



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/faker/default/omniauth.rb', line 225

def linkedin(name: nil, email: nil, uid: Number.number(digits: 6).to_s)
  auth = Omniauth.new(name: name, email: email)
  first_name = auth.first_name.downcase
  last_name = auth.last_name.downcase
  location = city_state
  description = Lorem.sentence
  token = Crypto.md5
  secret = Crypto.md5
  industry = Commerce.department
  url = "http://www.linkedin.com/in/#{first_name}#{last_name}"
  {
    provider: 'linkedin',
    uid: uid,
    info: {
      name: auth.name,
      email: auth.email,
      nickname: auth.name,
      first_name: auth.first_name,
      last_name: auth.last_name,
      location: location,
      description: description,
      image: image,
      phone: PhoneNumber.phone_number,
      headline: description,
      industry: industry,
      urls: {
        public_profile: url
      }
    },
    credentials: {
      token: token,
      secret: secret
    },
    extra: {
      access_token: {
        token: token,
        secret: secret,
        consumer: nil,
        params: {
          oauth_token: token,
          oauth_token_secret: secret,
          oauth_expires_in: Time.forward.to_i,
          oauth_authorization_expires_in: Time.forward.to_i
        },
        response: nil
      },
      raw_info: {
        firstName: auth.first_name,
        headline: description,
        id: uid,
        industry: industry,
        lastName: auth.last_name,
        location: {
          country: { code: Address.country_code.downcase },
          name: city_state.split(', ').first
        },
        pictureUrl: image,
        publicProfileUrl: url
      }
    }
  }
end

.twitter(name: nil, nickname: nil, uid: Number.number(digits: 6).to_s) ⇒ Hash

Generate a mock Omniauth response from Twitter.

Parameters:

  • name (String) (defaults to: nil)

    A specific name to return in the response.

  • nickname (String) (defaults to: nil)

    A specific nickname to return in the response.

  • uid (String) (defaults to: Number.number(digits: 6).to_s)

    A specific UID to return in the response.

Returns:

  • (Hash)

    An auth hash in the format provided by omniauth-twitter.

Available since:

  • 1.8.0



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/faker/default/omniauth.rb', line 142

def twitter(name: nil, nickname: nil, uid: Number.number(digits: 6).to_s)
  auth = Omniauth.new(name: name)
  nickname ||= auth.name.downcase.delete(' ')
  location = city_state
  description = Lorem.sentence
  {
    provider: 'twitter',
    uid: uid,
    info: {
      nickname: nickname,
      name: auth.name,
      location: location,
      image: image,
      description: description,
      urls: {
        Website: nil,
        Twitter: "https://twitter.com/#{nickname}"
      }
    },
    credentials: {
      token: Crypto.md5,
      secret: Crypto.md5
    },
    extra: {
      access_token: '',
      raw_info: {
        name: auth.name,
        listed_count: random_number_from_range(1..10),
        profile_sidebar_border_color: Color.hex_color,
        url: nil,
        lang: 'en',
        statuses_count: random_number_from_range(1..1000),
        profile_image_url: image,
        profile_background_image_url_https: image,
        location: location,
        time_zone: Address.city,
        follow_request_sent: random_boolean,
        id: uid,
        profile_background_tile: random_boolean,
        profile_sidebar_fill_color: Color.hex_color,
        followers_count: random_number_from_range(1..10_000),
        default_profile_image: random_boolean,
        screen_name: '',
        following: random_boolean,
        utc_offset: timezone,
        verified: random_boolean,
        favourites_count: random_number_from_range(1..10),
        profile_background_color: Color.hex_color,
        is_translator: random_boolean,
        friends_count: random_number_from_range(1..10_000),
        notifications: random_boolean,
        geo_enabled: random_boolean,
        profile_background_image_url: image,
        protected: random_boolean,
        description: description,
        profile_link_color: Color.hex_color,
        created_at: Time.backward.strftime('%a %b %d %H:%M:%S %z %Y'),
        id_str: uid,
        profile_image_url_https: image,
        default_profile: random_boolean,
        profile_use_background_image: random_boolean,
        entities: {
          description: {
            urls: []
          }
        },
        profile_text_color: Color.hex_color,
        contributors_enabled: random_boolean
      }
    }
  }
end