0

On my angular app I can use sso to oauth with google, twitter etc. It call my rails method to create the authentification token. This works, now I want to send the oauth token from my rails server to the angular.

My actual schema :

1) Angular : sso connexion button, call rails server -> 
2) Rails : token creation ->
3) Rails : send to specific url in angular front, in POST request ->
4) Angular : Get token from specific url, and perform connexion

But I don't know how to send the data like this,

Anybody as an idea?

1 Answer 1

1

Is 1) and 4) different Angular clients?

If you want to create a token by asking the rails server, the rails server should just pass the token back as part of the response.

You can do this in this manner. This is an example of a rails route/controller action that finds a certain user after they login.

def find
    user = User.find_by(email: params[:email])

    if user && user.authenticate(params[:password])
        return render json: {
            token: user.generate_auth_token,
            userId:  user.id
        }, status: 201
    else
        return render json: { error: 'Invalid Username or Password' }, status: 400
    end
end

I find the user by email, and then authenticate the password input, and then return a json object that has a token and other data I needed in angular like the userId.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.