Beau
2012-May-07 12:05 UTC
Creating an API key (many to many mapping), how would I go about it
Hey guys. I''m still a super rails noob, and trying to figure this out in relation to learning how to write controllers/models and where stuff should go. Basically I have my models set up with a many-to-many mapping of API keys to users. There''s three models here, users, api_keys_users, and api_keys. I''ve got a view/controller setup for the users. But have avoided doing it for the api_keys and api_keys_users tables. Manually I can create a API key and map it to a user using SQL but now I want to set it up for generation via the view. However I have no idea where the logic should go. Basically I want a "generate new api key" button on the show users page. This would create a unique entry in the api_key table. Then create an entry in the api_keys_users table with the id of the user and the id of the new key. Any pointers? -Beau -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/bFQDLWvKSgcJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-May-07 12:21 UTC
Re: Creating an API key (many to many mapping), how would I go about it
On 7 May 2012 13:05, Beau <beautrepp-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey guys. > > I''m still a super rails noob, and trying to figure this out in relation to > learning how to write controllers/models and where stuff should go.I suggest first working through some Rails tutorials. railstutorial.org is good and is free to use online. Once you have worked right through that, including doing all the exercises, then you will be better placed to get going. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Kevin Bedell
2012-May-07 14:30 UTC
Re: Creating an API key (many to many mapping), how would I go about it
Here''s a bit of information on building out an API using security and API keys. http://stackoverflow.com/questions/10470509/building-an-api-as-a-service/10470584#10470584 I''d use ''devise'' to manage api users with token auth enabled and have the token be their api key. I''ve done this before and it''s not too bad once you''ve gotten devise installed and configured correctly. -Kevin On Mon, May 7, 2012 at 8:05 AM, Beau <beautrepp-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey guys. > > I''m still a super rails noob, and trying to figure this out in relation to > learning how to write controllers/models and where stuff should go. > > Basically I have my models set up with a many-to-many mapping of API keys to > users. There''s three models here, users, api_keys_users, and api_keys. I''ve > got a view/controller setup for the users. But have avoided doing it for the > api_keys and api_keys_users tables. Manually I can create a API key and map > it to a user using SQL but now I want to set it up for generation via the > view. > > However I have no idea where the logic should go. Basically I want a > "generate new api key" button on the show users page. This would create a > unique entry in the api_key table. Then create an entry in the > api_keys_users table with the id of the user and the id of the new key. > > Any pointers? > > -Beau > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/bFQDLWvKSgcJ. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
beau trepp
2012-May-10 00:03 UTC
Re: Creating an API key (many to many mapping), how would I go about it
Ideally I''m viewing this as a fairly simple feature to add. Also I''m hoping this will help Mr solidify best practice for how to do things. Where I''m getting confused is what should be creating the user/key entries. I could make this part of the options for creating a key( aka passing in a user-id) and failing if it doesn''t exist etc. Then creating the mapping on after-save for the key. Or I could implement this as its own controller, and put some of the logic in there. On May 7, 2012 10:30 PM, "Kevin Bedell" <kbedell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Here''s a bit of information on building out an API using security and API > keys. > > > http://stackoverflow.com/questions/10470509/building-an-api-as-a-service/10470584#10470584 > > I''d use ''devise'' to manage api users with token auth enabled and have > the token be their api key. > > I''ve done this before and it''s not too bad once you''ve gotten devise > installed and configured correctly. > > -Kevin > > On Mon, May 7, 2012 at 8:05 AM, Beau <beautrepp-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hey guys. > > > > I''m still a super rails noob, and trying to figure this out in relation > to > > learning how to write controllers/models and where stuff should go. > > > > Basically I have my models set up with a many-to-many mapping of API > keys to > > users. There''s three models here, users, api_keys_users, and > api_keys. I''ve > > got a view/controller setup for the users. But have avoided doing it for > the > > api_keys and api_keys_users tables. Manually I can create a API key and > map > > it to a user using SQL but now I want to set it up for generation via the > > view. > > > > However I have no idea where the logic should go. Basically I want a > > "generate new api key" button on the show users page. This would create a > > unique entry in the api_key table. Then create an entry in the > > api_keys_users table with the id of the user and the id of the new key. > > > > Any pointers? > > > > -Beau > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To view this discussion on the web visit > > https://groups.google.com/d/msg/rubyonrails-talk/-/bFQDLWvKSgcJ. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-May-10 07:33 UTC
Re: Creating an API key (many to many mapping), how would I go about it
On 10 May 2012 01:03, beau trepp <beautrepp-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ideally I''m viewing this as a fairly simple feature to add. Also I''m hoping > this will help Mr solidify best practice for how to do things. > > Where I''m getting confused is what should be creating the user/key entries. > I could make this part of the options for creating a key( aka passing in a > user-id) and failing if it doesn''t exist etc. Then creating the mapping on > after-save for the key. Or I could implement this as its own controller, and > put some of the logic in there.I would use the create action of the keys controller, since that is what it is doing, if I understand correctly. Colin> > On May 7, 2012 10:30 PM, "Kevin Bedell" <kbedell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> Here''s a bit of information on building out an API using security and API >> keys. >> >> >> http://stackoverflow.com/questions/10470509/building-an-api-as-a-service/10470584#10470584 >> >> I''d use ''devise'' to manage api users with token auth enabled and have >> the token be their api key. >> >> I''ve done this before and it''s not too bad once you''ve gotten devise >> installed and configured correctly. >> >> -Kevin >> >> On Mon, May 7, 2012 at 8:05 AM, Beau <beautrepp-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Hey guys. >> > >> > I''m still a super rails noob, and trying to figure this out in relation >> > to >> > learning how to write controllers/models and where stuff should go. >> > >> > Basically I have my models set up with a many-to-many mapping of API >> > keys to >> > users. There''s three models here, users, api_keys_users, and >> > api_keys. I''ve >> > got a view/controller setup for the users. But have avoided doing it for >> > the >> > api_keys and api_keys_users tables. Manually I can create a API key and >> > map >> > it to a user using SQL but now I want to set it up for generation via >> > the >> > view. >> > >> > However I have no idea where the logic should go. Basically I want a >> > "generate new api key" button on the show users page. This would create >> > a >> > unique entry in the api_key table. Then create an entry in the >> > api_keys_users table with the id of the user and the id of the new key. >> > >> > Any pointers? >> > >> > -Beau >> > >> > -- >> > You received this message because you are subscribed to the Google >> > Groups >> > "Ruby on Rails: Talk" group. >> > To view this discussion on the web visit >> > https://groups.google.com/d/msg/rubyonrails-talk/-/bFQDLWvKSgcJ. >> > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. >> > To unsubscribe from this group, send email to >> > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group at >> > http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.