oauth

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 6 Imported by: 0

README

Azure OAuth2 Token

Go module for retrieving bearer access-token for accessing azure-api

Reference: https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#request-an-access-token-with-a-client_secret

Usage

Require

Add the module to your go.mod:

require github.com/gamepat/azure-oauth2-token v0.2.0
Examples

Get access-token:

import (
    "log"
    auth "github.com/gamepat/azure-oauth2-token"
)

func main() {
    cfg := auth.AuthConfig{
        ClientID:     "<YOUR_CLIENT_ID>",
        ClientSecret: "<YOUR_CLIENT_SECRET>",
        ClientScope:  "<YOUR_CLIENT_SCOPE>",
    }

    token, err := auth.RequestAccessToken("<YOUR_AZ_TENANT_ID>", cfg)
    if err != nil {
        log.Fatalf("error: %v", err)
    }
    log.Println(token)
}

Get access-token infos:

import (
    "log"
    auth "github.com/gamepat/azure-oauth2-token"
)

func main() {
    cfg := auth.AuthConfig{
        ClientID:     "<YOUR_CLIENT_ID>",
        ClientSecret: "<YOUR_CLIENT_SECRET>",
        ClientScope:  "<YOUR_CLIENT_SCOPE>",
    }

    tokenInfo, err := auth.RequestAccessTokenInfo("<YOUR_AZ_TENANT_ID>", cfg)
    if err != nil {
        log.Fatalf("error: %v", err)
    }
    log.Println(tokenInfo)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestAccessToken

func RequestAccessToken(tenantId string, config AuthConfig) (string, error)

Types

type AuthConfig

type AuthConfig struct {
	ClientID     string
	ClientSecret string
	ClientScope  string
}

===== Types =====

type TokenResponseSuccess added in v0.2.0

type TokenResponseSuccess struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
}

func RequestAccessTokenInfo added in v0.2.0

func RequestAccessTokenInfo(tenantId string, config AuthConfig) (*TokenResponseSuccess, error)

Jump to

Keyboard shortcuts

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