 

Ueberauth.Strategy.VK – Ueberauth VK Strategy v0.3.0

try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }

Toggle Sidebar

Toggle Theme

Ueberauth VK Strategy v0.3.0

 Ueberauth.Strategy.VK

 

 [View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk.ex#L1 "View Source")

=========================================================================================================================================================================

VK Strategy for Überauth.

### 

 Setup

Create an VK application for you to use.

Register a new application at: [VK devs](https://vk.com/dev) and get the `client_id` and `client_secret`.

Include the provider in your configuration for Ueberauth

```

config :ueberauth, Ueberauth,

  providers: [

    vk: { Ueberauth.Strategy.VK, [] }

  ]

```

Then include the configuration for github.

```

config :ueberauth, Ueberauth.Strategy.VK.OAuth,

  client_id: System.get_env("VK_CLIENT_ID"),

  client_secret: System.get_env("VK_CLIENT_SECRET"),

```

If you haven’t already, create a pipeline and setup routes for your callback handler

```

pipeline :auth do

  Ueberauth.plug "/auth"

end

scope "/auth" do

  pipe_through [:browser, :auth]

  get "/:provider/callback", AuthController, :callback

end

```

Create an endpoint for the callback where you will handle the [`Ueberauth.Auth`](https://hexdocs.pm/ueberauth/0.5.0/Ueberauth.Auth.html) struct

```

defmodule MyApp.AuthController do

  use MyApp.Web, :controller

  def callback_phase(%{ assigns: %{ ueberauth_failure: fails } } = conn, _params) do

    # do things with the failure

  end

  def callback_phase(%{ assigns: %{ ueberauth_auth: auth } } = conn, params) do

    # do things with the auth

  end

end

```

You can edit the behaviour of the Strategy by including some options when you register your provider.

You can customize [multiple fields](https://vk.com/dev/auth_sites), such as `default_scope`, `default_display`, `default_state`, `profile_fields`, `uid_field`

```

config :ueberauth, Ueberauth,

  providers: [

    vk: { Ueberauth.Strategy.VK, [

      default_scope: "email,friends,video,offline",

      default_display: "popup",

      default_state: "secret-state-value",

      uid_field: :email

    ] }

  ]

```

Default is empty (“”) which “Grants read-only access to public information (includes public user profile info, public repository info, and gists)”

[Link to this section](#summary)

 Summary

==========================================

[Functions](#functions)

------------------------

[auth(conn)](#auth/1)

[credentials(conn)](#credentials/1)

Includes the credentials from the VK response

[default\_options()](#default_options/0)

[extra(conn)](#extra/1)

Stores the raw information (including the token) obtained from

the vk callback

[handle\_request!(conn)](#handle_request!/1)

Handles initial request for VK authentication

[info(conn)](#info/1)

Fetches the fields to populate the info section of the

[`Ueberauth.Auth`](https://hexdocs.pm/ueberauth/0.5.0/Ueberauth.Auth.html) struct

[uid(conn)](#uid/1)

Fetches the uid field from the response

[Link to this section](#functions)

 Functions

==============================================

[Link to this function](#auth/1 "Link to this function")

auth(conn)

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk.ex#L65 "View Source")

[Link to this function](#credentials/1 "Link to this function")

credentials(conn)

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk.ex#L148 "View Source")

Includes the credentials from the VK response.

[Link to this function](#default_options/0 "Link to this function")

default\_options()

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk.ex#L65 "View Source")

[Link to this function](#extra/1 "Link to this function")

extra(conn)

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk.ex#L188 "View Source")

Stores the raw information (including the token) obtained from

the vk callback.

[Link to this function](#handle_request!/1 "Link to this function")

handle\_request!(conn)

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk.ex#L83 "View Source")

Handles initial request for VK authentication.

[Link to this function](#info/1 "Link to this function")

info(conn)

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk.ex#L166 "View Source")

Fetches the fields to populate the info section of the

[`Ueberauth.Auth`](https://hexdocs.pm/ueberauth/0.5.0/Ueberauth.Auth.html) struct.

[Link to this function](#uid/1 "Link to this function")

uid(conn)

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk.ex#L136 "View Source")

Fetches the uid field from the response.



 

Ueberauth.Strategy.VK.OAuth – Ueberauth VK Strategy v0.3.0

try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }

Toggle Sidebar

Toggle Theme

Ueberauth VK Strategy v0.3.0

 Ueberauth.Strategy.VK.OAuth

 

 [View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk/oauth.ex#L1 "View Source")

=====================================================================================================================================================================================

OAuth2 for VK.

Add `client_id` and `client_secret` to your configuration:

```

config :ueberauth, Ueberauth.Strategy.VK.OAuth,

  client_id: System.get_env("VK_APP_ID"),

  client_secret: System.get_env("VK_APP_SECRET")

```

[Link to this section](#summary)

 Summary

==========================================

[Functions](#functions)

------------------------

[authorize\_url(client, params)](#authorize_url/2)

[authorize\_url!(params \\ [], opts \\ [])](#authorize_url!/2)

Provides the authorize url for the request phase of Ueberauth.

No need to call this usually

[client(opts \\ [])](#client/1)

Construct a client for requests to vk.com

[get\_token(client, params, headers)](#get_token/3)

[get\_token!(params \\ [], opts \\ [])](#get_token!/2)

[Link to this section](#functions)

 Functions

==============================================

[Link to this function](#authorize_url/2 "Link to this function")

authorize\_url(client, params)

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk/oauth.ex#L60 "View Source")

[Link to this function](#authorize_url!/2 "Link to this function")

authorize\_url!(params \\ [], opts \\ [])

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk/oauth.ex#L45 "View Source")

Provides the authorize url for the request phase of Ueberauth.

No need to call this usually.

[Link to this function](#client/1 "Link to this function")

client(opts \\ [])

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk/oauth.ex#L30 "View Source")

Construct a client for requests to vk.com

This will be setup automatically for you in [`Ueberauth.Strategy.VK`](Ueberauth.Strategy.VK.html).

These options are only useful for usage outside the normal callback phase

of Ueberauth.

[Link to this function](#get_token/3 "Link to this function")

get\_token(client, params, headers)

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk/oauth.ex#L64 "View Source")

[Link to this function](#get_token!/2 "Link to this function")

get\_token!(params \\ [], opts \\ [])

[View Source](https://github.com/sobolevn/ueberauth_vk/blob/master/lib/ueberauth/strategy/vk/oauth.ex#L51 "View Source")

