b2c

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 12 Imported by: 0

README

Azure AD B2C SDK for Go

Tests Coverage

This SDK provides a set of functions to automate Azure B2C

  • Patch Azure AD Application to meet B2C requirements
  • Build and Deploy policies
  • Create Policy Keys and Certificates

The project has been inspired by

Getting started

This project uses Go modules for versioning and dependency management.

To add the latest version to your go.mod file, execute the following command.

go get github.com/Schumann-IT/azure-b2c-sdk-for-go

For more detailed usage examples, please checkout

Usage

  • create config file
- name: test
  settings:
    SomeVariable: SomeTestContent 
- name: prod
  settings:
    SomeVariable: SomeProdContent 
  • create some policies
src/
├─ local/
│  ├─ base.xml 
│  ├─ signupsignin.xml 
│  ├─ passwordreset.xml
├─ base.xml 
├─ extension.xml 

Build policies
package main

import (
	"log"

	"github.com/schumann-it/azure-b2c-sdk-for-go"
)

func main() {
	service, err := b2c.NewServiceFromConfigFile("environments.yaml")
	service.MustWithSourceDir("src")
	service.MustWithTargetDir("build")
	if err != nil {
		log.Fatalf("failed to create service: %w", err)
	}
	env := "environment_name"
	err = service.BuildPolicies("environment_name")
	if err != nil {
		log.Fatalf("failed to build policies for environment %s: %w", env, err)
	}
}
Deploy policies
package main

import (
	"log"
	
	"github.com/schumann-it/azure-b2c-sdk-for-go"
)

func main() {
    service, err := b2c.NewServiceFromConfigFile("environments.yaml")
	service.MustWithSourceDir("src")
	service.MustWithTargetDir("build")
    if err != nil {
		log.Fatalf("failed to create service: %w", err)
    }

	env := "test"
    err = service.DeployPolicies(env)
    if err != nil {
		log.Fatalf("failed to deploy policies for environment %s: %w", env, err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	TenantInformation models.TenantInformationable
	// contains filtered or unexported fields
}

Service represents a service that provides operations related to environments and policies.

func NewServiceFromConfigFile added in v0.7.0

func NewServiceFromConfigFile(cp string) (*Service, error)

NewServiceFromConfigFile creates a new instance of Service by loading the environment configuration from the provided file path and initializing the necessary variables. It returns a pointer to the Service instance and an error, if any.

func (*Service) BuildPolicies

func (s *Service) BuildPolicies(en string) error

BuildPolicies builds policies for a given environment. It reads the configuration file for the specified environment, processes the settings, and writes the policies to the target directory. Parameters:

  • en: the name of the environment

Returns:

  • error: an error if any occurred during the process

func (*Service) CreateGraphClientFromDefaultAzureCredential added in v0.7.0

func (s *Service) CreateGraphClientFromDefaultAzureCredential() error

func (*Service) CreateGraphClientFromEnvironment added in v0.7.0

func (s *Service) CreateGraphClientFromEnvironment() error

CreateGraphClientFromEnvironment creates a new instance of the Microsoft Graph service client using environment variable configuration. It returns a pointer to the ServiceClient instance and an error if the creation fails.

func (*Service) DeletePolicies

func (s *Service) DeletePolicies() error

DeletePolicies deletes policies for a given environment. It finds the configuration file for the specified environment, creates a graph client, and calls the DeletePolicies method on the client. Parameters:

  • en: the name of the environment

Returns:

  • error: an error if any occurred during the process

func (*Service) DeployPolicies

func (s *Service) DeployPolicies(en string) error

DeployPolicies deploys policies for a given environment. It finds the configuration file for the specified environment, creates a graph client, and uploads batches of policies.

Parameters:

  • en: the name of the environment

Returns:

  • error: an error if any occurred during the deployment

func (*Service) FindConfig added in v0.7.0

func (s *Service) FindConfig(n string) (*environment.Config, error)

FindConfig searches for the environment configuration with the specified name. It returns a pointer to the Config instance and an error, if the environment is not found.

func (*Service) GetGraphClient added in v0.7.0

func (s *Service) GetGraphClient() *msgraph.ServiceClient

func (*Service) ListPolicies

func (s *Service) ListPolicies() error

ListPolicies retrieves a list of policies for a given environment

Parameters: - en: the name of the environment

Returns: - error: an error if any occurred during the process.

func (*Service) MustWithSourceDir added in v0.8.0

func (s *Service) MustWithSourceDir(dir string)

func (*Service) MustWithTargetDir added in v0.8.0

func (s *Service) MustWithTargetDir(dir string)

func (*Service) WithEnvironments added in v0.7.0

func (s *Service) WithEnvironments(environments []environment.Config)

func (*Service) WithSourceDir added in v0.7.0

func (s *Service) WithSourceDir(dir string) error

func (*Service) WithTargetDir added in v0.7.0

func (s *Service) WithTargetDir(dir string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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