@@ -52,21 +52,31 @@ func attemptKubeloginAuthFlow(asset *inventory.Asset, config *rest.Config) error
5252 return errors .Wrap (err , "failed to get chained token credential for Azure AKS authentication" )
5353 }
5454
55- scope := serverAppId + defaultScope
56- token , err := chainedToken .GetToken (context .Background (), policy.TokenRequestOptions {
57- Scopes : []string {scope },
58- })
55+ rawToken , err := GetKubeloginBearerToken (chainedToken )
5956 if err != nil {
6057 return errors .Wrap (err , "failed to get access token for Azure AKS authentication" )
6158 }
6259
63- log .Debug ().Msg ("got access token" )
64-
65- config .BearerToken = token .Token
60+ config .BearerToken = rawToken
6661
6762 // clear the exec provider since the code above bypasses the need to run the command
6863 // `kubelogin get-token --server-id {serverAppId}` since that would require the kubelogin CLI tool to be present
6964 config .ExecProvider = nil
7065
7166 return nil
7267}
68+
69+ // attempt to get a bearer token using the kubelogin flow and attach it to the rest config
70+ func GetKubeloginBearerToken (token azcore.TokenCredential ) (string , error ) {
71+ log .Debug ().Msg ("aks kubelogin> attempting to get a bearer token using the kubelogin flow" )
72+ scope := serverAppId + defaultScope
73+ rawToken , err := token .GetToken (context .Background (), policy.TokenRequestOptions {
74+ Scopes : []string {scope },
75+ })
76+ if err != nil {
77+ return "" , errors .Wrap (err , "failed to get access token for Azure AKS authentication" )
78+ }
79+
80+ log .Debug ().Msg ("aks kubelogin> got access token" )
81+ return rawToken .Token , nil
82+ }
0 commit comments