auth

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2021 License: MIT Imports: 9 Imported by: 3

README

Auth

Authentication with social networks, information about the user

Supported:

  • Apple
  • Google
  • Facebook
  • VK

Usage

Input: token and auth type
import "github.com/rosberry/auth"

ud, err := auth.Auth(googleToken, auth.AuthTypeGoogle)

OR if you want check token audience:

import "github.com/rosberry/auth"

ud, err := auth.AuthWithCheckAUD(googleToken, audience, auth.AuthTypeGoogle)

Apple, Google: JWT token (id_token) Facebook, VK: access_token

Result: user details
UserDetails struct {
		ID        string
		FirstName string
		LastName  string
		UserName  string
		Email     string
		Picture   string
    }
Important
  • VK don't sent email in user information
  • Apple don't include username (firstname and lastname) in JWT token

About

This project is owned and maintained by Rosberry. We build mobile apps for users worldwide 🌏.

Check out our open source projects, read our blog or give us a high-five on 🐦 @rosberryapps.

License

This project is available under the MIT license. See the LICENSE file for more info.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotValidAudience = errors.New("not valid audience")
View Source
var Leeway int64 = 10

Leeway in seconds (for issuedAt and ExpiresAt)

Functions

This section is empty.

Types

type Apple

type Apple struct {
}

type AppleTokenInfo

type AppleTokenInfo struct {
	Sub   string `json:"sub"`
	Email string `json:"email"`
	jwt.StandardClaims
}

func (*AppleTokenInfo) Valid

func (c *AppleTokenInfo) Valid() error

type AuthService

type AuthService interface {
	// contains filtered or unexported methods
}

type Claim

type Claim struct {
	jwt.StandardClaims
}

type Facebook

type Facebook struct{}

type Google

type Google struct {
}

type GoogleTokenInfo

type GoogleTokenInfo struct {
	Sub       string `json:"sub"`
	Name      string `json:"name"`
	FirstName string `json:"given_name"`
	LastName  string `json:"family_name"`
	Email     string `json:"email"`
	Picture   string `json:"picture"`
	jwt.StandardClaims
}

func (*GoogleTokenInfo) Valid

func (c *GoogleTokenInfo) Valid() error

type Type

type Type uint

Type - social network

const (
	//AuthTypeGoogle - auth with Google
	AuthTypeGoogle Type = iota + 1
	//AuthTypeApple - auth with Apple
	AuthTypeApple
	//AuthTypeFacebook - auth with Facebook
	AuthTypeFacebook
	//AuthTypeVK - auth with VK
	AuthTypeVK
)

type UserDetails

type UserDetails struct {
	ID        string
	FirstName string
	LastName  string
	UserName  string
	Email     string
	Picture   string
}

UserDetails - information about user from social network

func Auth

func Auth(token string, authType Type) (userDetails *UserDetails, err error)

Auth returning user details by token and auth type

func AuthWithCheckAUD

func AuthWithCheckAUD(token string, aud string, authType Type) (userDetails *UserDetails, err error)

type VK

type VK struct{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL