Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manually calling /oauth/token route from registration #846

Closed
pswenson opened this issue Jun 2, 2016 · 3 comments
Closed

manually calling /oauth/token route from registration #846

pswenson opened this issue Jun 2, 2016 · 3 comments

Comments

@pswenson
Copy link

pswenson commented Jun 2, 2016

I'd like to combine registration with login to automatically log a user in after they are registered.

currently we call a registration route and then make the client do a second call to the doorkeeper magic route /oauth/token to login.

Could someone point me in the right direction to whatever code gets called in the /oauth/token rails route so I can call the code in my registration route and pass back the auth token?

thanks!

@igorkorepanov
Copy link

@pswenson

access_token = Doorkeeper::AccessToken.create(
   resource_owner_id: user_id,
   refresh_token: generate_refresh_token,
   expires_in: Doorkeeper.configuration.access_token_expires_in.to_i,
   scopes: ''
)
render json: {
   access_token: access_token.token,
   token_type: 'bearer',
   expires_in: access_token.expires_in,
   refresh_token: access_token.refresh_token,
   created_at: access_token.created_at.to_time.to_i
}
def generate_refresh_token
   loop do
      token = SecureRandom.hex(32)
      break token unless Doorkeeper::AccessToken.exists?(refresh_token: token)
   end
end 

@tute tute closed this as completed Jul 6, 2016
@tute
Copy link
Contributor

tute commented Jul 6, 2016

Thanks!

Consider asking about it in https://stackoverflow.com/questions/tagged/doorkeeper as well, where you will get attention from more people than in this issue tracker.

@HoseonRyu
Copy link

Another way is to use a doorkeeper helper function without defining a generate_refresh_token function.

Doorkeeper::OAuth::Helpers::UniqueToken.generate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants