apps

package
v0.0.0-...-c9f6891 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

README

Third Party Application Service

This service handle the creation, update, read and delete of third party applications. This applications can use pantahub oauth to authenticate their users and ask permission to different scopes inside pantahub base and can create their own scopes.

For most of the endpoints you will need a TOKEN to identify the owner of the application

Login
TOKEN=`http localhost:12365/auth/login username=user1 password=user1 | json token`

Retrive Pantahub avaliable scopes (Public endpoint)

curl --request GET \
  --url http://localhost:12365/apps/scopes \
  --header 'content-type: application/json'

Response:

[
  {
    "id": "all",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Complete Access"
  },
  {
    "id": "user.readonly",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Read only user"
  },
  {
    "id": "user.write",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Write only user"
  },
  {
    "id": "devices",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Read/Write devices"
  },
  {
    "id": "devices.readonly",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Read only devices"
  },
  {
    "id": "devices.write",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Write only devices"
  },
  {
    "id": "devices.change",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Update devices"
  },
  {
    "id": "objects",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Read/Write only objects"
  },
  {
    "id": "objects.readonly",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Read only objects"
  },
  {
    "id": "objects.write",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Write only objects"
  },
  {
    "id": "objects.change",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Update objects"
  },
  {
    "id": "trails",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Read/Write only trails"
  },
  {
    "id": "trails.readonly",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Read only trails"
  },
  {
    "id": "trails.write",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Write only trails"
  },
  {
    "id": "trails.change",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Update trails"
  },
  {
    "id": "metrics",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Read/Write only metrics"
  },
  {
    "id": "metrics.readonly",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Read only metrics"
  },
  {
    "id": "metrics.write",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Write only metrics"
  },
  {
    "id": "metrics.change",
    "service": "prn:pantahub.com:apis:/base",
    "description": "Update metrics"
  }
]

Create App

In order to create an app you need to send a json with this 3 obligatory properties:

  • type: One application can have two types (public|condidential) (more about that in here)[https://tools.ietf.org/html/rfc6749#section-2.1].
  • redirect_uris: This is an array of string with the URLs where can redirect the oauth service to sent the token or code.
  • scopes: this is an array of scopes, this set a approved list of scopes that can be asked to the user to give permission.
curl --request POST \
  --url http://localhost:12365/apps/ \
  --header 'authorization: Bearer $TOKEN' \
  --header 'content-type: application/json' \
  --data '{
	"type": "public",
	"redirect_uris": ["http://localhost/return_url"],
	"scopes": [
		{
			"id": "all",
			"service": "prn:pantahub.com:apis:/base"
		}
	]
}'

Response:

{
  "id": "5e0a658db0acd7109320fbe0",
  "type": "public",
  "nick": "secretly_better_grouper",
  "prn": "prn:pantahub.com:apis:/5e0a658db0acd7109320fbe0",
  "owner": "prn:::accounts:/5dfaac1b883859b4de940ca9",
  "owner-nick": "highercomve",
  "secret": "ct6bzdrzhaya7ezc75wy2ocuw6qz1v",
  "redirect_uris": [
    "http://localhost/return_url"
  ],
  "scopes": [
    {
      "id": "all",
      "service": "prn:pantahub.com:apis:/base",
      "description": "Complete Access"
    }
  ],
  "time-created": "2019-12-30T21:01:01.253338883Z",
  "time-modified": "2019-12-30T21:01:01.253338883Z"
}

Get all apps of a user

curl --request GET \
  --url http://localhost:12365/apps/ \
  --header 'authorization: Bearer $TOKEN' \
  --header 'content-type: application/json'

Get app by ID

curl --request GET \
  --url http://localhost:12365/apps/5e0a658db0acd7109320fbe0 \
  --header 'authorization: Bearer $TOKEN' \
  --header 'content-type: application/json'

Update app

curl --request PUT \
  --url http://localhost:12365/apps/5e0a658db0acd7109320fbe0 \
  --header 'authorization: Bearer $TOKEN' \
  --header 'content-type: application/json' \
  --data '{
	"type": "public",
	"redirect_uris": [
		"http://posibleappurl.com/oauth2/cb",
		"https://posibleappurl.com/oauth2/cb"
	],
	"scopes": [
		{
			"id": "all",
			"service": "prn:pantahub.com:apis:/base",
			"description": "Complete Access"
		},
		{
			"id": "programs.all",
			"description": "Read/write programs from the thirdparty application"
		}
	] 
}'

Delete APP

curl --request DELETE \
  --url http://localhost:12365/apps/5e0a658db0acd7109320fbe0 \
  --header 'authorization: Bearer $TOKEN' \
  --header 'content-type: application/json'

Documentation

Overview

Package apps package to manage extensions of the oauth protocol

Package apps package to manage extensions of the oauth protocol

Package apps package to manage extensions of the oauth protocol

Package apps package to manage extensions of the oauth protocol

Package apps package to manage extensions of the oauth protocol

Package apps package to manage extensions of the oauth protocol

Index

Constants

View Source
const (
	// AppTypeConfidential define a confidential client for oauth
	AppTypeConfidential = "confidential"

	// AppTypePublic define a public client for oauth
	AppTypePublic = "public"

	// DBCollection db collection name for thirdparty apps
	DBCollection = "pantahub_apps"

	// Prn name convection for the prn
	Prn = "prn:::apps:/"
)

Variables

This section is empty.

Functions

func AccessCodePayload

func AccessCodePayload(ctx context.Context, owner, serviceName, responseType, scopes string, accountPayload map[string]interface{}, database *mongo.Database) (map[string]interface{}, error)

AccessCodePayload get accesscode payload for application

func GetAppPayload

func GetAppPayload(ctx context.Context, serviceID string, database *mongo.Database) (map[string]interface{}, error)

GetAppPayload get app payload as account

func SearchExposedScopes

func SearchExposedScopes(ctx context.Context, database *mongo.Database) ([]utils.Scope, error)

SearchExposedScopes search all third party app by id or prn

Types

type App

type App struct {
	API *rest.Api
	// contains filtered or unexported fields
}

App thirdparty application manager

func New

func New(jwtMiddleware *jwt.JWTMiddleware, mongoClient *mongo.Client) *App

New create a new thirparty apps manager api

type CreateAppPayload

type CreateAppPayload struct {
	Type          string        `json:"type"`
	Nick          string        `json:"nick"`
	Name          string        `json:"name"`
	RedirectURIs  []string      `json:"redirect_uris,omitempty"`
	Scopes        []utils.Scope `json:"scopes,omitempty"`
	ExposedScopes []utils.Scope `json:"exposed_scopes,omitempty" bson:"exposed_scopes,omitempty"`
}

CreateAppPayload create app json payload

type TPApp

type TPApp struct {
	ID                  primitive.ObjectID `json:"id" bson:"_id"`
	Name                string             `json:"name" bson:"name"`
	Type                string             `json:"type" bson:"type"`
	Nick                string             `json:"nick" bson:"nick"`
	Prn                 string             `json:"prn" bson:"prn"`
	Owner               string             `json:"owner"`
	OwnerNick           string             `json:"owner-nick,omitempty" bson:"owner-nick,omitempty"`
	Secret              string             `json:"secret,omitempty" bson:"secret"`
	RedirectURIs        []string           `json:"redirect_uris,omitempty" bson:"redirect_uris,omitempty"`
	Scopes              []utils.Scope      `json:"scopes,omitempty" bson:"scopes,omitempty"`
	ExposedScopes       []utils.Scope      `json:"exposed_scopes,omitempty" bson:"exposed_scopes,omitempty"`
	ExposedScopesLength int                `bson:"exposed_scopes_length,omit"`
	TimeCreated         time.Time          `json:"time-created" bson:"time-created"`
	TimeModified        time.Time          `json:"time-modified" bson:"time-modified"`
	DeletedAt           *time.Time         `json:"deleted-at,omitempty" bson:"deleted-at,omitempty"`
}

TPApp OAuth App Type

func CreateOrUpdateApp

func CreateOrUpdateApp(ctx context.Context, tpApp *TPApp, database *mongo.Database) (*TPApp, error)

CreateOrUpdateApp a new third party app

func LoginAsApp

func LoginAsApp(serviceID, secret string, database *mongo.Database) (*TPApp, error)

LoginAsApp using and application id and secret

func SearchApp

func SearchApp(ctx context.Context, owner string, id string, database *mongo.Database) (*TPApp, int, error)

SearchApp search third party app by id or prn

func SearchApps

func SearchApps(ctx context.Context, owner string, id string, database *mongo.Database) ([]TPApp, error)

SearchApps search all third party app by id or prn

Jump to

Keyboard shortcuts

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