A
A
alexnotonfire2015-09-15 12:38:06
API
alexnotonfire, 2015-09-15 12:38:06

How to make authentication through classmates in Angularjs?

I need to implement authentication through the social network classmates on my project using Angularjs. Does anyone know what tools to use for this purpose? So far I have not found anything suitable on the Internet. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
Zaporozhchenko Oleg, 2015-09-16
@alexnotonfire

We did it on Ember.js, but the meaning is the same - you can not use the framework at all.
https://github.com/incubus/omniauth-odnoklassniki - we set ourselves a gem for authentication.
By clicking on the button, we open a new window with the authentication address Code
example on Ember.js but the meaning should be clear

SomeApp.SocialLoginButtonView = Ember.View.extend(
  tagName: "a"
  attributeBindings: ['href']

  click: (e)->
    e.preventDefault()
    provider  = $(e.currentTarget).attr('href')

    url = "/users/auth/#{provider}?transition_to_root=true"
    window.open(
      url, '_blank',
      'width=600,height=500,location=yes,resizable=yes,scrollbars=yes'
    )
)

Controller example
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  layout 'blank'

  def facebook
    sign_in_with_oauth_data(request.env['omniauth.auth'])
  end

  def twitter
    sign_in_with_oauth_data(request.env['omniauth.auth'])
  end

  private

  def sign_in_with_oauth_data(oauth_data)
    unless user_signed_in?
      user =  User.find_or_create_with_oauth(oauth_data)
      sign_in :user, user
      MailWorker.perform_in(1.hour, user.id, :account_dropoff)
    end

    @success = current_user.register_social_profile(normalize_oauth_data(oauth_data))
    @service_name = oauth_data.provider

    render 'shared/social_authentication'
  end

  def normalize_oauth_data(oauth_data)
    { service_name: oauth_data.provider, uid: oauth_data.uid, access_token: oauth_data.credentials.token, secret_key: oauth_data.credentials.secret }
  end
end

The controller renders the view - javascript that sends data to the parent window and closes the authorization window
<script type="text/javascript" charset="UTF-8">
  <% if @success %>
      window.opener.SomeApp.sendSuccess()
  <% else %>
    window.opener.SomeApp.sendFailure()
  <% end %>

  window.close();
</script>

M
Mikhail Osher, 2015-09-15
@miraage

Take any oauth2 for angular and write an implementation for OK.
Or look towards rails omniauth odnoklassniki.

D
Drm, 2015-09-15
@Drm

I think you are here https://apiok.ru/wiki/pages/viewpage.action?pageId...
You will hardly find ready-made solutions, but if you work with the API, you can do authentication through any social network

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question