What do the lambda's in the options do? #1

Closed
tinco opened this Issue Sep 30, 2012 · 8 comments

2 participants

@tinco

Hi could you give an example as to how I should populate the options hash? All the arguments seem to be obligatory, but it's a bit unclear what they should be.

It would help if you would take tent.is as an example, what would the get_app_id and on_app_created options look like?

Thanks for creating this!

@tinco

So it's morning and maybe I'm thinking a bit more clearly. Should they be used for storing the app id and authentication information in the database? If I return nil on get_app_id, will it just create a new app id for every session?

@jvatic
Tent member

Here is an example:

use OmniAuth::Strategies::Tent, {
  :app => {
    :name => 'FooApp',
    :description => 'Does amazing foos with your data',
    :icon => 'https://example.com/icon.png',
    :url => 'https://example.com',
    :scopes => {
      :write_profile => "Uses an app profile section to describe foos",
      :read_followings => "Calculates foos based on your followings"
      :read_posts => "Calculates foos based on your status posts"
    }
  },
  :profile_info_types => %w( https://tent.io/types/info/core/v0.1.0 https://tent.io/types/info/basic/v0.1.0 ),
  :post_types => %w( https://tent.io/types/post/status/v0.1.0 ),
  :notification_url => ENV['NOTIFICATION_URL'].to_s,
  :get_app_id => lambda { |entity|
    if user = MyUserModel.first(:entity => entity)
      user.app_id
    end
  }
}

Keep in mind I haven't fully tested this yet, but feel free to start using it and report any issues you find.

See the Tent.io docs and the tent-client-ruby. Both will help you understand what's going on here.

@tinco

Alright, I get that, but that leaves on_app_created, I get the idea that I should save the app here, but I have to associate the app with a user too right? The lambda doesn't get the user passed in and the entity is not in the app details returned, so how should I associate the app with a user?

@jvatic
Tent member

Good point, I've added the entity to the arguments passed to on_app_created.

use OmniAuth::Strategies::Tent, {
  ...
  :on_app_created => lambda { |app, entity| MyUserModel.create(:entity => entity, :app => app) }
}
@tinco

Thanks I think that covers this issue :)

@tinco tinco closed this Sep 30, 2012
@tinco

Hey, sorry to bother you with this again but I think this has regressed. It now gets called with the app representation, but it doesn't include the entity. I think either the uid of the app representation has to be set before calling the lambda or the entity has to be passed to this lambda :)

@tinco tinco reopened this Oct 7, 2012
@jvatic jvatic pushed a commit that closed this issue Oct 7, 2012
Jesse Stuart Fix: include entity as second argument when calling on_app_created
callback fixes #1
c1e30cb
@jvatic jvatic closed this in c1e30cb Oct 7, 2012
@jvatic
Tent member

This is fixed btw (apparently Github doesn't send out emails when closing an issue via a commit.)

@tinco

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment