简体   繁体   中英

How to get the auth URL from an OmniAuth provider without redirect

How do you get the URL that OmniAuth redirect to when you go to /auth/twitter ?

I am building an API server and just want to pass the URL in JSON to the client so it can do whatever it needs to with the URL.

I think what I want is the result of the strategy's request_phase as that looks to be the auth URL, but how do I get that in a new controller so I can do:

class MyOauthController < ApplicationController
  # GET /my_oauth/signin/twitter.json
  def signin
    url = ???
    render json: {signin_url: url}
  end

Is there a clean way to do this?

Yes, Omniauth provides a helper function for you:

user_omniauth_authorize_path(key)
# for your case
user_omniauth_authorize_path("twitter")

Check out their Devise overview .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM